File Coverage

blib/lib/Validation/Class/Directive/MaxLength.pm
Criterion Covered Total %
statement 20 20 100.0
branch 5 6 83.3
condition 4 6 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 34 38 89.4


line stmt bran cond sub pod time code
1             # ABSTRACT: MaxLength Directive for Validation Class Field Definitions
2              
3             package Validation::Class::Directive::MaxLength;
4              
5 109     109   52881 use strict;
  109         370  
  109         3132  
6 109     109   611 use warnings;
  109         254  
  109         2867  
7              
8 109     109   604 use base 'Validation::Class::Directive';
  109         251  
  109         10477  
9              
10 109     109   801 use Validation::Class::Util;
  109         278  
  109         794  
11              
12             our $VERSION = '7.900059'; # VERSION
13              
14              
15             has 'mixin' => 1;
16             has 'field' => 1;
17             has 'multi' => 0;
18             has 'message' => '%s must not contain more than %s characters';
19              
20             sub validate {
21              
22 59     59 0 331 my $self = shift;
23              
24 59         167 my ($proto, $field, $param) = @_;
25              
26 59 100 66     298 if (defined $field->{max_length} && defined $param) {
27              
28 55         277 my $max_length = $field->{max_length};
29              
30 55 50 66     403 if ( $field->{required} || $param ) {
31              
32 55 100       223 if (length($param) > $max_length) {
33              
34 6         50 $self->error(@_, $max_length);
35              
36             }
37              
38             }
39              
40             }
41              
42 59         174 return $self;
43              
44             }
45              
46             1;
47              
48             __END__