| 1 | package HTML::Widget::Constraint::Time; | ||
| 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::Time - Time Constraint | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | my $c = $widget->constraint( 'Time', 'hour', 'minute', 'second' ); | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | Time 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 ( $hour, $min, $sec ) = @{ $self->names }; | ||
| 33 | my $h = $params->{$hour} || 0; | ||
| 34 | my $m = $params->{$min} || 0; | ||
| 35 | my $s = $params->{$sec} || 0; | ||
| 36 | return [] unless ( $h && $m && $s ); | ||
| 37 | my $results = []; | ||
| 38 | |||
| 39 | unless ( $h =~ /^\d+$/ | ||
| 40 | && $m =~ /^\d+$/ | ||
| 41 | && $s =~ /^\d+$/ | ||
| 42 | && Date::Calc::check_time( $h, $m, $s ) ) | ||
| 43 | { | ||
| 44 | push @$results, HTML::Widget::Error->new( | ||
| 45 | { name => $hour, message => $self->mk_message } ); | ||
| 46 | push @$results, HTML::Widget::Error->new( | ||
| 47 | { name => $min, message => $self->mk_message } ); | ||
| 48 | push @$results, HTML::Widget::Error->new( | ||
| 49 | { name => $sec, 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; |