File Coverage

blib/lib/Input/Validator/Constraint/Date.pm
Criterion Covered Total %
statement 18 18 100.0
branch 4 4 100.0
condition 5 8 62.5
subroutine 4 4 100.0
pod 1 1 100.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package Input::Validator::Constraint::Date;
2              
3 1     1   25293 use strict;
  1         2  
  1         40  
4 1     1   7 use warnings;
  1         1  
  1         28  
5              
6 1     1   7 use base 'Input::Validator::Constraint';
  1         1  
  1         565  
7              
8             require Time::Local;
9              
10             sub is_valid {
11 4     4 1 446 my ($self, $value) = @_;
12              
13 4         7 my %args = @{$self->args};
  4         21  
14              
15 4   50     14 my $re = $args{split} || '/';
16 4         23 my ($year, $month, $day) = split($re, $value);
17              
18 4 100 66     43 return 0 unless $year && $month && $day;
      66        
19              
20 2         3 eval { Time::Local::timegm(0, 0, 0, $day, $month - 1, $year); };
  2         12  
21              
22 2 100       322 return $@ ? 0 : 1;
23             }
24              
25             1;
26             __END__