Widget/Constraint/Date.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 69 CC 4 SCAR 24.0
CC
4
Cov
0%
process
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
1 package HTML::Widget::Constraint::Date;
2  
3 use warnings;
4 use strict;
5 use base 'HTML::Widget::Constraint';
6 use Date::Calc;
7  
8 =head1 NAME
9  
10 HTML::Widget::Constraint::Date - Date Constraint
11  
12 =head1 SYNOPSIS
13  
14 my $c = $widget->constraint( 'Date', 'year', 'month', 'day' );
15  
16 =head1 DESCRIPTION
17  
18 Date Constraint.
19  
20 =head1 METHODS
21  
22 =head2 process
23  
24 =cut
25  
26 sub process {
27 my ( $self, $w, $params ) = @_;
28  
29 return []
30 unless ( $self->names && @{ $self->names } == 3 );
31  
32 my ( $year, $month, $day ) = @{ $self->names };
33 my $y = $params->{$year};
34 my $m = $params->{$month};
35 my $d = $params->{$day};
36 return [] unless ( $y && $m && $d );
37 my $results = [];
38  
39 unless ( $y =~ /^\d+$/
40 && $m =~ /^\d+$/
41 && $d =~ /^\d+$/
42 && Date::Calc::check_date( $y, $m, $d ) )
43 {
44 push @$results, HTML::Widget::Error->new(
45 { name => $year, message => $self->mk_message } );
46 push @$results, HTML::Widget::Error->new(
47 { name => $month, message => $self->mk_message } );
48 push @$results, HTML::Widget::Error->new(
49 { name => $day, message => $self->mk_message } );
50 }
51 return $results;
52 }
53  
54 =head1 AUTHOR
55  
56 Sebastian Riedel, C<sri@oook.de>
57  
58 =head1 LICENSE
59  
60 This library is free software, you can redistribute it and/or modify it under
61 the same terms as Perl itself.
62  
63 =cut
64  
65 1;