| HTML-Widget documentation | Contained in the HTML-Widget distribution. |
HTML::Widget::Constraint::Date - Date Constraint
my $c = $widget->constraint( 'Date', 'year', 'month', 'day' );
Date Constraint.
Sebastian Riedel, sri@oook.de
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| HTML-Widget documentation | Contained in the HTML-Widget distribution. |
package HTML::Widget::Constraint::Date; use warnings; use strict; use base 'HTML::Widget::Constraint'; use Date::Calc;
sub process { my ( $self, $w, $params ) = @_; return [] unless ( $self->names && @{ $self->names } == 3 ); my ( $year, $month, $day ) = @{ $self->names }; my $y = $params->{$year}; my $m = $params->{$month}; my $d = $params->{$day}; return [] unless ( $y && $m && $d ); my $results = []; unless ( $y =~ /^\d+$/ && $m =~ /^\d+$/ && $d =~ /^\d+$/ && Date::Calc::check_date( $y, $m, $d ) ) { push @$results, HTML::Widget::Error->new( { name => $year, message => $self->mk_message } ); push @$results, HTML::Widget::Error->new( { name => $month, message => $self->mk_message } ); push @$results, HTML::Widget::Error->new( { name => $day, message => $self->mk_message } ); } return $results; }
1;