File Coverage

blib/lib/Interface/Validation/Directive/Validator/Between.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             # Interface::Validation Validator Directive Between
2             package Interface::Validation::Directive::Validator::Between;
3              
4 1     1   42273 use Bubblegum;
  1         200785  
  1         7  
5 1     1   809487 use Function::Parameters;
  1         2765  
  1         8  
6 1     1   727 use Moose;
  0            
  0            
7              
8             use Bubblegum::Constraints -minimal;
9              
10             our $VERSION = '0.01_01'; # VERSION
11              
12             extends 'Interface::Validation::Directive';
13             with 'Interface::Validation::DirectiveRole::Execute::OnValidate';
14             with 'Interface::Validation::DirectiveRole::Field';
15             with 'Interface::Validation::DirectiveRole::Mixin::Default';
16             with 'Interface::Validation::DirectiveRole::Validator';
17              
18             method error {
19             my @args = $self->args_list;
20             my $range = join ' and ', @args;
21             return "#{label} must contain between $range characters";
22             }
23              
24             method validate {
25             my $exec = _object shift;
26             my $field = _object shift;
27              
28             my $param = shift;
29             my @args = $self->args_list;
30              
31             my $min = _number $args[0];
32             my $max = _number $args[1];
33              
34             my $value = length($param);
35             unless ($value >= $min && $value <= $max) {
36             return $self->exception($exec, $field, $param);
37             }
38              
39             return;
40             }
41              
42             1;