HTML::Widget::Constraint::Date - Date Constraint


HTML-Widget documentation Contained in the HTML-Widget distribution.

Index


Code Index:

NAME

Top

HTML::Widget::Constraint::Date - Date Constraint

SYNOPSIS

Top

    my $c = $widget->constraint( 'Date', 'year', 'month', 'day' );

DESCRIPTION

Top

Date Constraint.

METHODS

Top

process

AUTHOR

Top

Sebastian Riedel, sri@oook.de

LICENSE

Top

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;