File Coverage

blib/lib/Input/Validator/Constraint/Callback.pm
Criterion Covered Total %
statement 21 22 95.4
branch 7 8 87.5
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 35 37 94.5


line stmt bran cond sub pod time code
1             package Input::Validator::Constraint::Callback;
2              
3 1     1   30877 use strict;
  1         2  
  1         40  
4 1     1   5 use warnings;
  1         3  
  1         29  
5              
6 1     1   5 use base 'Input::Validator::Constraint';
  1         2  
  1         610  
7              
8             sub is_valid {
9 3     3 1 418 my ($self, $value) = @_;
10              
11 3         14 my $cb = $self->args;
12              
13 3         9 my ($ok, $custom_error) = $cb->($value);
14 3 100       29 return $ok if $ok;
15              
16 2 100       10 if (defined $custom_error) {
17 1         3 $self->error($custom_error);
18             }
19              
20 2         8 return 0;
21             }
22              
23             sub error {
24 2     2 1 3 my $self = shift;
25              
26 2 100       14 unless (@_) {
27 1 50       10 return $self->{error} if defined $self->{error};
28 0         0 return $self->SUPER::error;
29             }
30              
31 1         3 $self->{error} = $_[0];
32              
33 1         2 return $self;
34             }
35              
36             1;
37             __END__