| 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; |