Data-FormValidator-Constraints-DateTime-1.11000755000764000764 011403754464 21414 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/META.yml000444000764000764 141611403754464 23024 0ustar00mpetersmpeters000000000000--- abstract: 'D::FV constraints for dates and times' author: - 'Michael Peters ' build_requires: DateTime::Format::Builder: 0 configure_requires: Module::Build: 0.36 generated_by: 'Module::Build version 0.3603' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Data-FormValidator-Constraints-DateTime provides: Data::FormValidator::Constraints::DateTime: file: lib/Data/FormValidator/Constraints/DateTime.pm version: 1.11 recommends: DateTime::Format::MySQL: 0.0301 DateTime::Format::Pg: 0.050 requires: Data::FormValidator: 3.61 DateTime: 0.23 DateTime::Format::Strptime: 1.00 Exporter: 0 perl: v5.6.1 resources: license: http://dev.perl.org/licenses/ version: 1.11 Data-FormValidator-Constraints-DateTime-1.11/Changes000444000764000764 463411403754464 23053 0ustar00mpetersmpeters000000000000Revision history for Perl extension Data::FormValidator::Constraints::DateTime 1.11 (Jun 01, 2010) - Added missing copyright and license notification. 1.10 (May 13, 2010) - Fixed test failures that relied on hard coded future dates. [RT #57456, from iarnell] 1.09 (Dec. 19, 2005) - now using Scalar::Util::blessed to check if the $dfv is really an object before calling isa() to provide better diagnostics if the user does something they aren't supposed to - more doc improvements 1.08 (Dec. 12, 2005) - added DateTime::Format::Builder to 'build_requires' - no code changes 1.07 (Nov. 08, 2005) - added support for DateTime::Format objects where ever strptime(3) format strings are allowed - removed unnecessary dereferencing check 1.06 (Oct. 28, 2005) - minor doc fixes - fixed new higher-order constraints to work with CGI.pm instead of just a hashref - fixed new higher-order tests to be skipped if we are using D::FV 3.x 1.05 (Oct. 04, 2005) - fixed docs to use 'ref-less' parameters - other minor doc fixes - same code as 1.04 1.04 (Sep. 20, 2005) - fixed failing test when DateTime::Format::Pg is not installed 1.03 (Aug. 24, 2005) - added 4.0 style of higher-order constraints - removed examples of older styles 1.02 (Jul. 26, 2005) - added ymd_before_today() and ymd_after_today() routines 1.01 (Jul. 25, 2005) - added before_today() and after_today() routines 1.00 (Mar. 03, 2005) - added before_datetime(), after_datetime(), and between_datetimes() routines - 100% coverage tests - minor doc cleanups 0.06 (Feb. 22, 2005) - ymd_to_datetime() routine will now not accept empty strings as valid date portions 0.05 (Feb. 21, 2005) - added Changes to MANIFEST - added ymd_to_datetime() validation routine - more tests - minor doc corrections 0.04 (Feb. 19, 2005) - all routines can be used as either a 'constraint' or 'constraint_method' - more docs 0.03 (Feb. 18, 2005) - more tests added - database formats no longer require format params but will use the DateTime::Format::*->parse_*() methods if no format is given - minor doc corrections 0.02 (Feb. 18, 2005) - more tests added - DateTime::Format::MySQL and DateTime::Format::Pg are now not required, but recommended and only loaded when needed 0.01 (Feb. 17, 2005) - Initial Release Data-FormValidator-Constraints-DateTime-1.11/MANIFEST000444000764000764 35711403754464 22667 0ustar00mpetersmpeters000000000000Build.PL Changes lib/Data/FormValidator/Constraints/DateTime.pm Makefile.PL MANIFEST This list of files META.yml t/3x_databases.t t/3x_dates.t t/cgi_and_hashref.t t/databases.t t/dates.t t/datetime_format.t t/lib/DFVCDT/Test/FlexYear.pm Data-FormValidator-Constraints-DateTime-1.11/Build.PL000444000764000764 127611403754464 23053 0ustar00mpetersmpeters000000000000use Module::Build; my $build = Module::Build->new( module_name => 'Data::FormValidator::Constraints::DateTime', license => 'perl', requires => { 'perl' => '5.6.1', 'Data::FormValidator' => '3.61', 'DateTime' => '0.23', 'DateTime::Format::Strptime' => '1.00', 'Exporter' => 0, }, recommends => { 'DateTime::Format::MySQL' => '0.0301', 'DateTime::Format::Pg' => '0.050', }, build_requires => { 'DateTime::Format::Builder' => 0, }, create_makefile_pl => 'traditional', ); $build->create_build_script; Data-FormValidator-Constraints-DateTime-1.11/Makefile.PL000444000764000764 131611403754464 23524 0ustar00mpetersmpeters000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.3603 require 5.006001; use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Data::FormValidator::Constraints::DateTime', 'VERSION_FROM' => 'lib/Data/FormValidator/Constraints/DateTime.pm', 'PREREQ_PM' => { 'Data::FormValidator' => '3.61', 'DateTime' => '0.23', 'DateTime::Format::Builder' => 0, 'DateTime::Format::Strptime' => '1.00', 'Exporter' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Data-FormValidator-Constraints-DateTime-1.11/t000755000764000764 011403754464 21657 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/t/3x_dates.t000444000764000764 4047711403754464 23747 0ustar00mpetersmpeters000000000000use Test::More; use strict; use Data::FormValidator; use DateTime; plan(tests => 113); # 1 use_ok('Data::FormValidator::Constraints::DateTime'); Data::FormValidator::Constraints::DateTime->import(); my $format = '%m-%d-%Y'; my $good_date = '02-17-2005'; my $unreal_date = '02-31-2005'; my $bad_date = '0-312-005'; my $real_bad_date = '2'; my $today = DateTime->today->mdy('-'); # these are relative to the above $good_date; my $distant_future_date = DateTime->today->add(years => 100)->mdy('-'); my $future_date = DateTime->today->add(years => 2)->mdy('-'); my $past_date = '03-03-1979'; my $distant_past_date = '03-03-1879'; # 2..13 # to_datetime { my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [qw(good bad realbad unreal)], untaint_all_constraints => 1, ); my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, ); foreach my $as_method (0..1) { $profile{constraints} = _make_constraints( routine => 'to_datetime', as_method => $as_method, params => [\$format], inputs => [keys %data ], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); } }; # 14..33 # ymd_to_datetime { foreach my $as_method (0..1) { my %profile = ( validator_packages => [qw(Data::FormValidator::Constraints::DateTime)], required => [qw(my_year)], untaint_all_constraints => 1, ); my %data = ( my_year => 2005, my_month => 2, my_day => 17, ); $profile{constraints} = _make_constraints( routine => 'ymd_to_datetime', as_method => $as_method, params => ($as_method ? [qw(my_year my_month my_day)] : [qw(my_month my_day)]), inputs => ['my_year'], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('my_year'), 'ymd_to_datetime: correct'); isa_ok( $results->valid('my_year'), 'DateTime'); # now with hms $profile{constraints} = _make_constraints( routine => 'ymd_to_datetime', as_method => $as_method, params => ($as_method ? [qw(my_year my_month my_day my_hour my_min my_sec)] : [qw(my_month my_day my_hour my_min my_sec)]), inputs => ['my_year'], ); $data{my_hour} = 14; $data{my_min} = 6; $data{my_sec} = 14; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('my_year'), 'ymd_to_datetime: correct'); isa_ok( $results->valid('my_year'), 'DateTime'); # make sure it fails if the month is not a number $data{my_month} = ""; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_month} = undef; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_month} = 2; # reset the month # make sure it fails if the day is not a number $data{my_day} = ""; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_day} = undef; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_day} = "17"; # reset the day # make sure it fails the year is not a number $profile{constraints} = { 'my_month' => { ($as_method ? 'constraint_method' : 'constraint') => 'ymd_to_datetime', params => [qw(my_year my_month my_day my_hour my_min my_sec)], }, }; $profile{required} = ['my_month']; $data{my_year} = ""; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_month'), 'ymd_to_datetime: invalid date'); $data{my_year} = undef; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_month'), 'ymd_to_datetime: invalid date'); } } # 34..43 # before_today { my %data = ( good => $past_date, bad => $future_date, today => $today, ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [keys %data], untaint_all_constraints => 1, ); foreach my $as_method (0..1) { $profile{constraints} = _make_constraints( routine => 'before_today', as_method => $as_method, params => [\$format], inputs => [keys %data], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->valid('today'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $past_date, 'DateTime stringifies correctly'); } } # 44..53 # after_today { my %data = ( good => $future_date, bad => $past_date, today => $today, ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [keys %data], untaint_all_constraints => 1, ); foreach my $as_method (0..1) { $profile{constraints} = _make_constraints( routine => 'after_today', as_method => $as_method, params => [\$format], inputs => [keys %data], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->valid('today'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $future_date, 'DateTime stringifies correctly'); } } # 54..57 # ymd_before_today { # split it up into ymd my @good_parts = split(/-/, $past_date); my @bad_parts = split(/-/, $future_date); my @today_parts = split(/-/, $today); my %data = ( good_m => $good_parts[0], good_d => $good_parts[1], good_y => $good_parts[2], bad_m => $bad_parts[0], bad_d => $bad_parts[1], bad_y => $bad_parts[2], today_m => $today_parts[0], today_d => $today_parts[1], today_y => $today_parts[2], ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [qw(good_y bad_y today_y)], untaint_all_constraints => 1, constraints => { good_y => { constraint_method => 'ymd_before_today', params => [qw(good_y good_m good_d)], }, bad_y => { constraint_method => 'ymd_before_today', params => [qw(bad_y bad_m bad_d)], }, today_y => { constraint_method => 'ymd_before_today', params => [qw(today_y today_m today_d)], }, }, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good_y'), 'datetime expected valid'); ok( $results->invalid('bad_y'), 'datetime expected invalid'); ok( $results->valid('today_y'), 'datetime expected valid'); my $date = $results->valid('good_y'); isa_ok( $date, 'DateTime'); } # 58..61 # ymd_after_today { # split it up into ymd my @good_parts = split(/-/, $future_date); my @bad_parts = split(/-/, $past_date); my @today_parts = split(/-/, $today); my %data = ( good_m => $good_parts[0], good_d => $good_parts[1], good_y => $good_parts[2], bad_m => $bad_parts[0], bad_d => $bad_parts[1], bad_y => $bad_parts[2], today_m => $today_parts[0], today_d => $today_parts[1], today_y => $today_parts[2], ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [qw(good_y bad_y today_y)], untaint_all_constraints => 1, constraints => { good_y => { constraint_method => 'ymd_after_today', params => [qw(good_y good_m good_d)], }, bad_y => { constraint_method => 'ymd_after_today', params => [qw(bad_y bad_m bad_d)], }, today_y => { constraint_method => 'ymd_after_today', params => [qw(today_y today_m today_d)], }, }, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good_y'), 'datetime expected valid'); ok( $results->invalid('bad_y'), 'datetime expected invalid'); ok( $results->valid('today_y'), 'datetime expected valid'); my $date = $results->valid('good_y'); isa_ok( $date, 'DateTime'); } # 62..77 # before_datetime { my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, future => $distant_future_date, ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [keys %data], untaint_all_constraints => 1, ); foreach my $as_method (0..1) { $profile{constraints} = _make_constraints( routine => 'before_datetime', as_method => $as_method, params => [\$format, \$future_date], inputs => [keys %data], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); ok( $results->invalid('future'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); # test an invalid future_date $profile{constraints} = _make_constraints( routine => 'before_datetime', as_method => $as_method, params => [\$format, \$bad_date], inputs => [keys %data], ); $results = Data::FormValidator->check(\%data, \%profile); my @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); } } # 78..93 # after_datetime { my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, past => $distant_past_date, ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [keys %data], untaint_all_constraints => 1, ); foreach my $as_method (0..1) { $profile{constraints} = _make_constraints( routine => 'after_datetime', as_method => $as_method, params => [\$format, \$past_date], inputs => [keys %data], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); ok( $results->invalid('past'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); # test an invalid past_date $profile{constraints} = _make_constraints( routine => 'after_datetime', as_method => $as_method, params => [\$format, \$bad_date], inputs => [keys %data], ); $results = Data::FormValidator->check(\%data, \%profile); my @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); } } # 94..113 # between_datetimes { my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, outside_past => $distant_past_date, outside_future => $distant_future_date, ); my %profile = ( validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => [keys %data], untaint_all_constraints => 1, ); foreach my $as_method (0..1) { $profile{constraints} = _make_constraints( routine => 'between_datetimes', as_method => $as_method, params => [\$format, \$past_date, \$future_date], inputs => [keys %data], ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); ok( $results->invalid('outside_past'), 'datetime expected invalid'); ok( $results->invalid('outside_future'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); # test an invalid past_date $profile{constraints} = _make_constraints( routine => 'between_datetimes', as_method => $as_method, params => [\$format, \$bad_date, \$future_date], inputs => [keys %data], ); $results = Data::FormValidator->check(\%data, \%profile); my @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); # test an invalid future_date $profile{constraints} = _make_constraints( routine => 'between_datetimes', as_method => $as_method, params => [\$format, \$past_date, \$bad_date], inputs => [keys %data], ); $results = Data::FormValidator->check(\%data, \%profile); @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); } } sub _make_constraints { my %args = @_; my ($method, $as_method, @params) = @_; my %constraints = (); foreach my $input (@{$args{inputs}}) { if( $args{as_method} ) { $constraints{$input} = { constraint_method => $args{routine}, params => $args{params}, }; } else { my @tmp_params = @{$args{params}}; $constraints{$input} = { constraint => $args{routine}, params => [$input, @tmp_params], }; } } return \%constraints; }; Data-FormValidator-Constraints-DateTime-1.11/t/datetime_format.t000444000764000764 215511403754464 25350 0ustar00mpetersmpeters000000000000use Test::More; use Data::FormValidator; use DateTime; use lib 't/lib'; use DFVCDT::Test::FlexYear; use Data::FormValidator::Constraints::DateTime qw(:all); use Carp qw(confess); $SIG{__DIE__} = \*Carp::confess; my $DFV_4 = $Data::FormValidator::VERSION =~ /^4\./ ? 1 : 0; # only run these tests if we have D::FV 4.x if( $DFV_4 ) { plan(tests => 6); } else { plan(skip_all => 'D::FV 4.x not installed'); } my $profile = { required => [qw(good bad)], constraint_methods => { good => to_datetime(DFVCDT::Test::FlexYear->new()), bad => to_datetime(DFVCDT::Test::FlexYear->new()), }, untaint_all_constraints => 1, }; # with 'Y' format my $data = { good => '11/07/2005', bad => '2/31/1', }; my $results = Data::FormValidator->check($data, $profile); ok($results->valid('good')); ok($results->invalid('bad')); isa_ok($results->valid('good'), 'DateTime'); # with 'y' format $data->{good} = '11/07/05'; $results = Data::FormValidator->check($data, $profile); ok($results->valid('good')); ok($results->invalid('bad')); isa_ok($results->valid('good'), 'DateTime'); Data-FormValidator-Constraints-DateTime-1.11/t/3x_databases.t000444000764000764 1631411403754464 24567 0ustar00mpetersmpeters000000000000use Test::More; use strict; use Data::FormValidator; use DateTime; plan(tests => 64); # 1 use_ok('Data::FormValidator::Constraints::DateTime'); Data::FormValidator::Constraints::DateTime->import(); my $format = '%m-%d-%Y'; my $good_date = '02-17-2005'; my $unreal_date = '02-31-2005'; my $bad_date = '0-312-005'; my $real_bad_date = '2'; my @inputs = qw(good bad realbad unreal); my $profile = { validator_packages => ['Data::FormValidator::Constraints::DateTime'], required => \@inputs, untaint_all_constraints => 1, }; my $DATA = { good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, }; my $WITHOUT_PARAMS = 0; my $WITH_PARAMS = 1; my $WITH_PARAMS_METHOD = 2; my ($results, $date); # test to see if we have DateTime::Format::MySQL my $HAVE_DT_FORMAT_MYSQL = 0; eval { require DateTime::Format::MySQL }; $HAVE_DT_FORMAT_MYSQL = 1 if( !$@ ); SKIP: { skip('DateTime::Format::MySQL not installed', 45) unless $HAVE_DT_FORMAT_MYSQL; # 2..16 # to_mysql_datetime { # with params and without both as a constraint_method and as a constraint foreach my $option ( $WITHOUT_PARAMS, $WITH_PARAMS, $WITH_PARAMS_METHOD, ) { $profile->{constraints} = _make_constraints('to_mysql_datetime', $option); my %data = %$DATA; $data{good} = '2005-02-17 00:00:00' if( $option == $WITHOUT_PARAMS ); $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_datetime expected valid'); ok( $results->invalid('bad'), 'mysql_datetime expected invalid'); ok( $results->invalid('realbad'), 'mysql_datetime expected invalid'); ok( $results->invalid('unreal'), 'mysql_datetime expected invalid'); $date = $results->valid('good'); is($date, '2005-02-17 00:00:00', 'mysql_datetime correct format'); } } # 17..31 # to_mysql_date { # with params and without both as a constraint_method and as a constraint foreach my $option ( $WITHOUT_PARAMS, $WITH_PARAMS, $WITH_PARAMS_METHOD ) { $profile->{constraints} = _make_constraints('to_mysql_date', $option); my %data = %$DATA; $data{good} = '2005-02-17' if( $option == $WITHOUT_PARAMS ); $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_date expected valid'); ok( $results->invalid('bad'), 'mysql_date expected invalid'); ok( $results->invalid('realbad'), 'mysql_date expected invalid'); ok( $results->invalid('unreal'), 'mysql_date expected invalid'); $date = $results->valid('good'); is($date, '2005-02-17', 'mysql_date correct format'); } } # 32..46 # to_mysql_timestamp { # with params and without both as a constraint_method and as a constraint foreach my $option ( $WITHOUT_PARAMS, $WITH_PARAMS, $WITH_PARAMS_METHOD ) { $profile->{constraints} = _make_constraints('to_mysql_timestamp', $option); my %data = %$DATA; $data{good} = '20050217000000' if( $option == $WITHOUT_PARAMS ); $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_timestamp expected valid'); ok( $results->invalid('bad'), 'mysql_timestamp expected invalid'); ok( $results->invalid('realbad'), 'mysql_timestamp expected invalid'); ok( $results->invalid('unreal'), 'mysql_timestamp expected invalid'); my $date = $results->valid('good'); is($date, '20050217000000', 'mysql_timestamp correct format'); } } } # 47..48 # let's remove DateTime::Format::MySQL from %INC (if it's there) and make # sure our constraints notice { my @SAVED_INC = (); my ($module, $path); if( $HAVE_DT_FORMAT_MYSQL ) { @SAVED_INC = @INC; @INC = (); $module = 'DateTime/Format/MySQL.pm'; $path = delete $INC{$module}; } # mysql_datetime $profile->{constraints} = _make_constraints('to_mysql_datetime', $WITHOUT_PARAMS); eval { $results = Data::FormValidator->check($DATA, $profile, $WITHOUT_PARAMS) }; like( $@, qr/DateTime::Format::MySQL is required/, 'missing module'); # mysql_date $profile->{constraints} = _make_constraints('to_mysql_date', $WITHOUT_PARAMS); eval { $results = Data::FormValidator->check($DATA, $profile) }; like( $@, qr/DateTime::Format::MySQL is required/, 'missing module'); if( $HAVE_DT_FORMAT_MYSQL ) { @INC = @SAVED_INC; $INC{$module} = $path; } } # test to see if we have DateTime::Format::Pg my $HAVE_DT_FORMAT_PG = 0; eval { require DateTime::Format::Pg }; $HAVE_DT_FORMAT_PG = 1 if( !$@ ); SKIP: { skip('DateTime::Format::Pg not installed', 15) unless $HAVE_DT_FORMAT_PG; # 49..63 # to_pg_datetime { # with params and without both as a constraint_method and as a constraint foreach my $option ( $WITHOUT_PARAMS, $WITH_PARAMS, $WITH_PARAMS_METHOD ) { my %data = %$DATA; $profile->{constraints} = _make_constraints('to_pg_datetime', $option); $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'pg_datetime expected valid'); ok( $results->invalid('bad'), 'pg_datetime expected invalid'); ok( $results->invalid('realbad'), 'pg_datetime expected invalid'); ok( $results->invalid('unreal'), 'pg_datetime expected invalid'); my $date = $results->valid('good'); like($date, qr/2005-02-17 00:00:00(\.000000000\+0000)?/, 'pg_datetime correct format'); } } } # 64 # let's remove DateTime::Format::Pg from %INC (if it's there) and make # sure our constraints notice { my @SAVED_INC = (); my ($module, $path); if( $HAVE_DT_FORMAT_PG ) { @SAVED_INC = @INC; @INC = (); $module = 'DateTime/Format/Pg.pm'; $path = delete $INC{$module}; } # pg_datetime $profile->{constraints} = _make_constraints('to_pg_datetime', $WITHOUT_PARAMS); eval { $results = Data::FormValidator->check($DATA, $profile, $WITHOUT_PARAMS) }; like( $@, qr/DateTime::Format::Pg is required/, 'missing module'); if( $HAVE_DT_FORMAT_PG ) { @INC = @SAVED_INC; $INC{$module} = $path; } } sub _make_constraints { my ($method, $option) = @_; my %constraints; foreach my $input (@inputs) { if( $option == $WITHOUT_PARAMS ) { $constraints{$input} = $method; } elsif( $option == $WITH_PARAMS ) { $constraints{$input} = { constraint => $method, params => [$input, \$format], }; } elsif( $option == $WITH_PARAMS_METHOD ) { $constraints{$input} = { constraint_method => $method, params => [\$format], }; } } return \%constraints; }; Data-FormValidator-Constraints-DateTime-1.11/t/databases.t000444000764000764 2244611403754464 24160 0ustar00mpetersmpeters000000000000use Test::More; use strict; use Data::FormValidator; use DateTime; my $DFV_4 = $Data::FormValidator::VERSION =~ /^4\./ ? 1 : 0; # only run these tests if we have D::FV 4.x if( $DFV_4 ) { plan(tests => 44); } else { plan(skip_all => 'D::FV 4.x not installed'); } # 1 use_ok('Data::FormValidator::Constraints::DateTime'); Data::FormValidator::Constraints::DateTime->import(':all'); my $format = '%m-%d-%Y'; my $good_date = '02-17-2005'; my $unreal_date = '02-31-2005'; my $bad_date = '0-312-005'; my $real_bad_date = '2'; my @inputs = qw(good bad realbad unreal); my $profile = { required => \@inputs, untaint_all_constraints => 1, }; my $DATA = { good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, }; my ($results, $date); # test to see if we have DateTime::Format::MySQL my $HAVE_DT_FORMAT_MYSQL = 0; eval { require DateTime::Format::MySQL }; $HAVE_DT_FORMAT_MYSQL = 1 if( !$@ ); SKIP: { skip('DateTime::Format::MySQL not installed', 30) unless $HAVE_DT_FORMAT_MYSQL; # 2..11 # to_mysql_datetime { # without a format param $profile->{constraint_methods} = { good => to_mysql_datetime(), unreal => to_mysql_datetime(), bad => to_mysql_datetime(), realbad => to_mysql_datetime(), }; # use local data my %data = %$DATA; $data{good} = '2005-02-17 00:00:00'; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_datetime expected valid'); ok( $results->invalid('bad'), 'mysql_datetime expected invalid'); ok( $results->invalid('realbad'), 'mysql_datetime expected invalid'); ok( $results->invalid('unreal'), 'mysql_datetime expected invalid'); $date = $results->valid('good'); is($date, '2005-02-17 00:00:00', 'mysql_datetime correct format'); # with a format param $profile->{constraint_methods} = { good => to_mysql_datetime($format), unreal => to_mysql_datetime($format), bad => to_mysql_datetime($format), realbad => to_mysql_datetime($format), }; %data = %$DATA; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_datetime expected valid'); ok( $results->invalid('bad'), 'mysql_datetime expected invalid'); ok( $results->invalid('realbad'), 'mysql_datetime expected invalid'); ok( $results->invalid('unreal'), 'mysql_datetime expected invalid'); $date = $results->valid('good'); is($date, '2005-02-17 00:00:00', 'mysql_datetime correct format'); } # 12..21 # to_mysql_date { # without a format param $profile->{constraint_methods} = { good => to_mysql_date(), unreal => to_mysql_date(), bad => to_mysql_date(), realbad => to_mysql_date(), }; # use local data my %data = %$DATA; $data{good} = '2005-02-17'; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_date expected valid'); ok( $results->invalid('bad'), 'mysql_date expected invalid'); ok( $results->invalid('realbad'), 'mysql_date expected invalid'); ok( $results->invalid('unreal'), 'mysql_date expected invalid'); $date = $results->valid('good'); is($date, '2005-02-17', 'mysql_date correct format'); # with a format param $profile->{constraint_methods} = { good => to_mysql_date($format), unreal => to_mysql_date($format), bad => to_mysql_date($format), realbad => to_mysql_date($format), }; %data = %$DATA; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_date expected valid'); ok( $results->invalid('bad'), 'mysql_date expected invalid'); ok( $results->invalid('realbad'), 'mysql_date expected invalid'); ok( $results->invalid('unreal'), 'mysql_date expected invalid'); $date = $results->valid('good'); is($date, '2005-02-17', 'mysql_date correct format'); } # 22..31 # to_mysql_timestamp { # without a format param $profile->{constraint_methods} = { good => to_mysql_timestamp(), unreal => to_mysql_timestamp(), bad => to_mysql_timestamp(), realbad => to_mysql_timestamp(), }; # use local data my %data = %$DATA; $data{good} = '20050217000000'; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_timestamp expected valid'); ok( $results->invalid('bad'), 'mysql_timestamp expected invalid'); ok( $results->invalid('realbad'), 'mysql_timestamp expected invalid'); ok( $results->invalid('unreal'), 'mysql_timestamp expected invalid'); my $date = $results->valid('good'); is($date, '20050217000000', 'mysql_timestamp correct format'); # with a format param $profile->{constraint_methods} = { good => to_mysql_timestamp($format), unreal => to_mysql_timestamp($format), bad => to_mysql_timestamp($format), realbad => to_mysql_timestamp($format), }; %data = %$DATA; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'mysql_timestamp expected valid'); ok( $results->invalid('bad'), 'mysql_timestamp expected invalid'); ok( $results->invalid('realbad'), 'mysql_timestamp expected invalid'); ok( $results->invalid('unreal'), 'mysql_timestamp expected invalid'); $date = $results->valid('good'); is($date, '20050217000000', 'mysql_timestamp correct format'); } } # 32..33 # let's remove DateTime::Format::MySQL from %INC (if it's there) and make # sure our constraints notice { my @SAVED_INC = (); my ($module, $path); if( $HAVE_DT_FORMAT_MYSQL ) { @SAVED_INC = @INC; @INC = (); $module = 'DateTime/Format/MySQL.pm'; $path = delete $INC{$module}; } # mysql_datetime $profile->{constraint_methods} = { good => to_mysql_datetime() }; eval { $results = Data::FormValidator->check($DATA, $profile) }; like( $@, qr/DateTime::Format::MySQL is required/, 'missing module'); # mysql_date $profile->{constraint_methods} = { good => to_mysql_date() }; eval { $results = Data::FormValidator->check($DATA, $profile) }; like( $@, qr/DateTime::Format::MySQL is required/, 'missing module'); if( $HAVE_DT_FORMAT_MYSQL ) { @INC = @SAVED_INC; $INC{$module} = $path; } } # test to see if we have DateTime::Format::Pg my $HAVE_DT_FORMAT_PG = 0; eval { require DateTime::Format::Pg }; $HAVE_DT_FORMAT_PG = 1 if( !$@ ); SKIP: { skip('DateTime::Format::Pg not installed', 10) unless $HAVE_DT_FORMAT_PG; # 34..43 # to_pg_datetime { # without a format param $profile->{constraint_methods} = { good => to_pg_datetime(), unreal => to_pg_datetime(), bad => to_pg_datetime(), realbad => to_pg_datetime(), }; # use local data my %data = %$DATA; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'pg_datetime expected valid'); ok( $results->invalid('bad'), 'pg_datetime expected invalid'); ok( $results->invalid('realbad'), 'pg_datetime expected invalid'); ok( $results->invalid('unreal'), 'pg_datetime expected invalid'); my $date = $results->valid('good'); like($date, qr/2005-02-17 00:00:00(\.000000000\+0000)?/, 'pg_datetime correct format'); # with a format param $profile->{constraint_methods} = { good => to_pg_datetime($format), unreal => to_pg_datetime($format), bad => to_pg_datetime($format), realbad => to_pg_datetime($format), }; $results = Data::FormValidator->check(\%data, $profile); ok( $results->valid('good'), 'pg_datetime expected valid'); ok( $results->invalid('bad'), 'pg_datetime expected invalid'); ok( $results->invalid('realbad'), 'pg_datetime expected invalid'); ok( $results->invalid('unreal'), 'pg_datetime expected invalid'); $date = $results->valid('good'); like($date, qr/2005-02-17 00:00:00(\.000000000\+0000)?/, 'pg_datetime correct format'); } } # 44 # let's remove DateTime::Format::Pg from %INC (if it's there) and make # sure our constraints notice { my @SAVED_INC = (); my ($module, $path); if( $HAVE_DT_FORMAT_PG ) { @SAVED_INC = @INC; @INC = (); $module = 'DateTime/Format/Pg.pm'; $path = delete $INC{$module}; } # pg_datetime $profile->{constraint_methods} = { good => to_pg_datetime() }; eval { $results = Data::FormValidator->check($DATA, $profile) }; like( $@, qr/DateTime::Format::Pg is required/, 'missing module'); if( $HAVE_DT_FORMAT_PG ) { @INC = @SAVED_INC; $INC{$module} = $path; } } Data-FormValidator-Constraints-DateTime-1.11/t/dates.t000444000764000764 3261611403754464 23331 0ustar00mpetersmpeters000000000000use Test::More; use strict; use Data::FormValidator; use DateTime; my $DFV_4 = $Data::FormValidator::VERSION =~ /^4\./ ? 1 : 0; # only run these tests if we have D::FV 4.x if( $DFV_4 ) { plan(tests => 61); } else { plan(skip_all => 'D::FV 4.x not installed'); } # 1 use_ok('Data::FormValidator::Constraints::DateTime'); Data::FormValidator::Constraints::DateTime->import(':all'); my $format = '%m-%d-%Y'; my $good_date = '02-17-2005'; my $unreal_date = '02-31-2005'; my $bad_date = '0-312-005'; my $real_bad_date = '2'; my $today = DateTime->today->mdy('-'); # these are relative to the above $good_date; my $distant_future_date = DateTime->today->add(years => 100)->mdy('-'); my $future_date = DateTime->today->add(years => 2)->mdy('-'); my $past_date = '03-03-1979'; my $distant_past_date = '03-03-1879'; # 2..7 # to_datetime { my %profile = ( required => [qw(good bad realbad unreal)], constraint_methods => { good => to_datetime($format), unreal => to_datetime($format), bad => to_datetime($format), realbad => to_datetime($format), }, untaint_all_constraints => 1, ); my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); } # 8..17 # ymd_to_datetime { my %profile = ( required => [qw(my_year)], constraint_methods => { my_year => ymd_to_datetime(qw(my_year my_month my_day)), }, untaint_all_constraints => 1, ); my %data = ( my_year => 2005, my_month => 2, my_day => 17, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('my_year'), 'ymd_to_datetime: correct'); isa_ok( $results->valid('my_year'), 'DateTime'); # now with hms $profile{constraint_methods}->{my_year} = ymd_to_datetime(qw(my_year my_month my_day my_hour my_min my_sec)); $data{my_hour} = 14; $data{my_min} = 6; $data{my_sec} = 14; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('my_year'), 'ymd_to_datetime: correct'); isa_ok( $results->valid('my_year'), 'DateTime'); # make sure it fails if the month is not a number $data{my_month} = ""; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_month} = undef; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_month} = 2; # reset the month # make sure it fails if the day is not a number $data{my_day} = ""; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_day} = undef; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_year'), 'ymd_to_datetime: invalid date'); $data{my_day} = "17"; # reset the day # make sure it fails the year is not a number $profile{constraint_methods} = { 'my_month' => ymd_to_datetime(qw(my_year my_month my_day my_hour my_min my_sec)), }; $profile{required} = ['my_month']; $data{my_year} = ""; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_month'), 'ymd_to_datetime: invalid date'); $data{my_year} = undef; $results = Data::FormValidator->check(\%data, \%profile); ok( $results->invalid('my_month'), 'ymd_to_datetime: invalid date'); } # 18..22 # before_today { my %data = ( good => $past_date, bad => $future_date, today => $today, ); my %profile = ( required => [qw(good bad today)], constraint_methods => { good => before_today($format), bad => before_today($format), today => before_today($format), }, untaint_all_constraints => 1, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->valid('today'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $past_date, 'DateTime stringifies correctly'); } # 23..27 # after_today { my %data = ( good => $future_date, bad => $past_date, today => $today, ); my %profile = ( required => [qw(good bad today)], constraint_methods => { good => after_today($format), bad => after_today($format), today => after_today($format), }, untaint_all_constraints => 1, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->valid('today'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $future_date, 'DateTime stringifies correctly'); } # 28..31 # ymd_before_today { # split it up into ymd my @good_parts = split(/-/, $past_date); my @bad_parts = split(/-/, $future_date); my @today_parts = split(/-/, $today); my %data = ( good_m => $good_parts[0], good_d => $good_parts[1], good_y => $good_parts[2], bad_m => $bad_parts[0], bad_d => $bad_parts[1], bad_y => $bad_parts[2], today_m => $today_parts[0], today_d => $today_parts[1], today_y => $today_parts[2], ); my %profile = ( required => [qw(good_y bad_y today_y)], untaint_all_constraints => 1, constraint_methods => { good_y => ymd_before_today(qw(good_y good_m good_d)), bad_y => ymd_before_today(qw(bad_y bad_m bad_d)), today_y => ymd_before_today(qw(today_y today_m today_d)), }, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good_y'), 'datetime expected valid'); ok( $results->invalid('bad_y'), 'datetime expected invalid'); ok( $results->valid('today_y'), 'datetime expected valid'); my $date = $results->valid('good_y'); isa_ok( $date, 'DateTime'); } # 32..35 # ymd_after_today { # split it up into ymd my @good_parts = split(/-/, $future_date); my @bad_parts = split(/-/, $past_date); my @today_parts = split(/-/, $today); my %data = ( good_m => $good_parts[0], good_d => $good_parts[1], good_y => $good_parts[2], bad_m => $bad_parts[0], bad_d => $bad_parts[1], bad_y => $bad_parts[2], today_m => $today_parts[0], today_d => $today_parts[1], today_y => $today_parts[2], ); my %profile = ( required => [qw(good_y bad_y today_y)], untaint_all_constraints => 1, constraint_methods => { good_y => ymd_after_today(qw(good_y good_m good_d)), bad_y => ymd_after_today(qw(bad_y bad_m bad_d)), today_y => ymd_after_today(qw(today_y today_m today_d)), }, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good_y'), 'datetime expected valid'); ok( $results->invalid('bad_y'), 'datetime expected invalid'); ok( $results->valid('today_y'), 'datetime expected valid'); my $date = $results->valid('good_y'); isa_ok( $date, 'DateTime'); } # 36..43 # before_datetime { my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, future => $distant_future_date, ); my %profile = ( required => [qw(good unreal bad realbad future)], constraint_methods => { good => before_datetime($format, $future_date), unreal => before_datetime($format, $future_date), bad => before_datetime($format, $future_date), realbad => before_datetime($format, $future_date), future => before_datetime($format, $future_date), }, untaint_all_constraints => 1, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); ok( $results->invalid('future'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); # test an invalid past date $profile{constraint_methods} = { bad => before_datetime($format, $bad_date) }; $profile{required} = ['bad']; $results = Data::FormValidator->check(\%data, \%profile); my @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); } # 44..51 # after_datetime { my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, past => $distant_past_date, ); my %profile = ( required => [qw(good unreal bad realbad past)], constraint_methods => { good => after_datetime($format, $past_date), unreal => after_datetime($format, $past_date), bad => after_datetime($format, $past_date), realbad => after_datetime($format, $past_date), past => after_datetime($format, $past_date), }, untaint_all_constraints => 1, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); ok( $results->invalid('past'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); # test an invalid future_date $profile{constraint_methods} = { bad => after_datetime($format, $bad_date) }; $profile{required} = ['bad']; $results = Data::FormValidator->check(\%data, \%profile); my @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); } # 52..61 # between_datetimes { my %data = ( good => $good_date, unreal => $unreal_date, bad => $bad_date, realbad => $real_bad_date, outside_past => $distant_past_date, outside_future => $distant_future_date, ); my %profile = ( required => [qw(good unreal bad realbad outside_past outside_future)], constraint_methods => { good => between_datetimes($format, $past_date, $future_date), unreal => between_datetimes($format, $past_date, $future_date), bad => between_datetimes($format, $past_date, $future_date), realbad => between_datetimes($format, $past_date, $future_date), outside_past => between_datetimes($format, $past_date, $future_date), outside_future => between_datetimes($format, $past_date, $future_date), }, untaint_all_constraints => 1, ); my $results = Data::FormValidator->check(\%data, \%profile); ok( $results->valid('good'), 'datetime expected valid'); ok( $results->invalid('bad'), 'datetime expected invalid'); ok( $results->invalid('realbad'), 'datetime expected invalid'); ok( $results->invalid('unreal'), 'datetime expected invalid'); ok( $results->invalid('outside_past'), 'datetime expected invalid'); ok( $results->invalid('outside_future'), 'datetime expected invalid'); my $date = $results->valid('good'); isa_ok( $date, 'DateTime'); is( "$date", $good_date, 'DateTime stringifies correctly'); # test an invalid past_date $profile{constraint_methods} = { bad => between_datetimes($format, $bad_date, $future_date) }; $profile{required} = ['bad']; $results = Data::FormValidator->check(\%data, \%profile); my @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); # test an invalid future_date $profile{constraint_methods} = { bad => between_datetimes($format, $past_date, $bad_date) }; $results = Data::FormValidator->check(\%data, \%profile); @any_valid = $results->valid(); is(scalar @any_valid, 0, 'no valid data'); } Data-FormValidator-Constraints-DateTime-1.11/t/cgi_and_hashref.t000444000764000764 357711403754464 25301 0ustar00mpetersmpeters000000000000use Test::More; use Data::FormValidator; use Data::FormValidator::Constraints::DateTime qw(ymd_to_datetime); use CGI; my $DFV_4 = $Data::FormValidator::VERSION =~ /^4\./ ? 1 : 0; plan( tests => 4); my %profile_4x = ( untaint_all_constraints => 1, required => [qw( start_year start_month start_day end_year end_month end_day )], constraint_methods => { start_year => ymd_to_datetime(qw(start_year start_month start_day)), end_year => ymd_to_datetime(qw(end_year end_month end_day)), }, ); my %profile_3x = ( untaint_all_constraints => 1, validator_packages => 'Data::FormValidator::Constraints::DateTime', required => [qw( start_year start_month start_day end_year end_month end_day )], constraints => { start_year => { constraint => 'ymd_to_datetime', params => [qw(start_year start_month start_day)], }, end_year => { constraint => 'ymd_to_datetime', params => [qw(end_year end_month end_day)], }, }, ); my %data = ( start_year => '2005', start_month => '12', start_day => '31', end_year => '2112', end_month => '1', end_day => '1', ); my $query = CGI->new(\%data); # 3.x interface # input as hashref ok(Data::FormValidator->check(\%data, \%profile_3x), "3.x from hashref"); # input as cgi query object ok(Data::FormValidator->check($query, \%profile_3x), "3.x from CGI query"); # skip these these unless we have 4.x installed SKIP: { skip('D::FV 4.x not installed', 2) unless( $DFV_4 ); # input as hashref ok(Data::FormValidator->check(\%data, \%profile_4x), "4.x from hashref"); # input as cgi query object ok(Data::FormValidator->check($query, \%profile_4x), "4.x from CGI query"); }; Data-FormValidator-Constraints-DateTime-1.11/t/lib000755000764000764 011403754464 22425 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/t/lib/DFVCDT000755000764000764 011403754464 23377 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/t/lib/DFVCDT/Test000755000764000764 011403754464 24316 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/t/lib/DFVCDT/Test/FlexYear.pm000444000764000764 54511403754464 26514 0ustar00mpetersmpeters000000000000package DFVCDT::Test::FlexYear; use DateTime::Format::Strptime; use DateTime::Format::Builder ( parsers => { parse_datetime => [ sub { eval { DateTime::Format::Strptime->new(pattern => '%m/%d/%Y')->parse_datetime($_[1]) } }, sub { eval { DateTime::Format::Strptime->new(pattern => '%m/%d/%y')->parse_datetime($_[1]) } }, ] } ); 1; Data-FormValidator-Constraints-DateTime-1.11/lib000755000764000764 011403754464 22162 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/lib/Data000755000764000764 011403754464 23033 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/lib/Data/FormValidator000755000764000764 011403754464 25604 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/lib/Data/FormValidator/Constraints000755000764000764 011403754464 30113 5ustar00mpetersmpeters000000000000Data-FormValidator-Constraints-DateTime-1.11/lib/Data/FormValidator/Constraints/DateTime.pm000444000764000764 7214511403754464 32333 0ustar00mpetersmpeters000000000000package Data::FormValidator::Constraints::DateTime; use strict; use DateTime; use DateTime::Format::Strptime; use Scalar::Util qw(blessed); use Exporter; use Carp qw(croak); our @ISA = qw(Exporter); our @EXPORT_OK = qw( to_datetime ymd_to_datetime before_today after_today ymd_before_today ymd_after_today before_datetime after_datetime between_datetimes to_mysql_datetime to_mysql_date to_mysql_timestamp to_pg_datetime ); our %EXPORT_TAGS = ( all => \@EXPORT_OK, mysql => [qw(to_mysql_datetime to_mysql_date to_mysql_timestamp)], pg => [qw(to_pg_datetime)], ); our $VERSION = '1.11'; =head1 NAME Data::FormValidator::Constraints::DateTime - D::FV constraints for dates and times =head1 DESCRIPTION This package provides constraint routines for L for dealing with dates and times. It provides an easy mechanism for validating dates of any format (using strptime(3)) and transforming those dates (as long as you 'untaint' the fields) into valid L objects, or into strings that would be properly formatted for various database engines. =head1 ABSTRACT use Data::FormValidator; use Data::FormValidator::Constraints::DateTime qw(:all); # create our profile my $profile = { required => [qw(my_date)], constraint_methods => { my_date => to_datetime('%D'), # in the format MM/DD/YYYY }, untaint_all_constraints => 1, }; # validate 'my_date' my $results = Data::FormValidator->check($my_input, $profile); if( $results->success ) { # if we got here then $results->valid('my_date') # is a valid DateTime object my $datetime = $results->valid('my_date'); . . } =head1 STRPTIME FORMATS Most of the validation routines provided by this module use strptime(3) format strings to know what format your date string is in before we can process it. You specify this format for each date you want to validate using by passing it to constraint generation routine (see the example above). We use L for this transformation. If you need a list of these formats (if you haven't yet committed them to memory) you can see the strptime(3) man page (if you are on a *nix system) or you can see the L documentation. There are however some routines that can live without the format param. These include routines which try and validate according to rules for a particular database (C<< to_mysql_* >> and C<< to_pg_* >>). If no format is provided, then we will attempt to validate according to the rules for that datatype in that database (using L and L). Here are some examples: without a format param my $profile = { required => [qw(my_date)], constraint_methods => { my_date => to_mysql_datetime(), }, }; with a format param my $profile = { required => [qw(my_date)], constraint_methods => { my_date => to_mysql_datetime('%m/%d/%Y'), }, }; =head2 DateTime::Format Objects Using strptime(3) format strings gives a lot of flexibility, but sometimes not enough. Suppose you have a web form that allows the user to input a date in the format '11/21/2006' or simply '11/21/06'. A simple format string is not enough. To take full advantage of the DateTime project, any place that you can pass in a strptime(3) format string, you can also pass in a L object. To solve the above problem you might have code that looks like this: # your formatter code package MyProject::DateTime::FlexYear; use DateTime::Format::Strptime; use DateTime::Format::Builder ( parsers => { parse_datetime => [ sub { eval { DateTime::Format::Strptime->new(pattern => '%m/%d/%Y')->parse_datetime($_[1]) } }, sub { eval { DateTime::Format::Strptime->new(pattern => '%m/%d/%y')->parse_datetime($_[1]) } }, ] } ); 1; # in your web validation code my $profile = { required => [qw(my_date)], constraint_methods => { my_date => to_mysql_datetime(MyProject::DateTime::FlexYear->new()), }, }; =head1 VALIDATION ROUTINES Following is the list of validation routines that are provided by this module. =head2 to_datetime The routine will validate the date aginst a strptime(3) format and change the date string into a DateTime object. This routine B have an accompanying L format param. If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub to_datetime { my $format = shift; # dereference stuff if we need to return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); return match_to_datetime($dfv, $format); } } sub match_to_datetime { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # get the DateTime my $dt = _get_datetime_from_strp($value, $format); return $dt; } sub _get_datetime_from_strp { my ($value, $format) = @_; $format = $$format if( ref $format eq 'SCALAR' ); my $formatter; # if we have a simple scalar for the format if( ! ref $format ) { # create the formatter $formatter = DateTime::Format::Strptime->new( pattern => $format ); # else we assume it's a DateTime::Format based object } else { $formatter = $format; } # create the DateTime object my $dt; eval { $dt = $formatter->parse_datetime($value); }; # set the formatter (if we can) so that the object # stringifies to the same format as we parsed $dt->set_formatter($formatter) if( $dt && $formatter->can('format_datetime') ); return $dt; } =head2 ymd_to_datetime This routine is used to take multiple inputs (one each for the year, month, and day) and combine them into a L object, validate the resulting date, and give you the resulting DateTime object in your C<< valid() >> results. It must recieve as C<< params >> the year, month, and day inputs in that order. You may also specify additional C<< params >> that will be interpretted as 'hour', 'minute' and 'second' values to use. If none are provided, then the time '00:00:00' will be used. my $profile = { required => [qw(my_year)], constraint_methods => { my_year => ymd_to_datetime(qw(my_year my_month my_day my_hour my_min my_sec)), }, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub ymd_to_datetime { my ($year, $month, $day, $hour, $min, $sec) = @_; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); my $data = $dfv->get_input_data(as_hashref => 1); return match_ymd_to_datetime( $dfv, _get_value($year, $data), _get_value($month, $data), _get_value($day, $data), _get_value($hour, $data), _get_value($min, $data), _get_value($sec, $data), ); }; } sub _get_value { my ($value, $data) = @_; if( $value && exists $data->{$value} ) { return $data->{$value}; } else { return $value; } } sub match_ymd_to_datetime { my ($dfv, $year, $month, $day, $hour, $min, $sec); # if we were called as a 'constraint_method' if( ref $_[0] ) { ($dfv, $year, $month, $day, $hour, $min, $sec) = @_; # else we were called as a 'constraint' } else { ($year, $month, $day, $hour, $min, $sec) = @_; } # make sure year, month and day are positive numbers if( defined $year && $year ne "" && defined $month && $month ne "" && defined $day && $day ne "" ) { # set the defaults for time if we don't have any $hour ||= 0; $min ||= 0; $sec ||= 0; my $dt; eval { $dt = DateTime->new( year => $year, month => $month, day => $day, hour => $hour, minute => $min, second => $sec, ); }; return $dt; } else { return; } } =head2 before_today This routine will validate the date and make sure it less than or equal to today (using C<< DateTime->today >>). It takes one param which is the format string for the date. If it validates and you tell D::FV to untaint this parameter it will be converted into a DateTime object. # make sure they weren't born in the future my $profile = { required => [qw(birth_date)], constraint_methods => { birth_date => before_today('%m/%d/%Y'), }, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub before_today { my $format = shift; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); return match_before_today($dfv, $format); }; } sub match_before_today { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # get the DateTime my $dt = _get_datetime_from_strp($value, $format); my $dt_target = DateTime->today(); # if we have valid DateTime objects and they have the correct # temporaral relationship if( $dt && $dt_target && $dt <= $dt_target ) { return $dt; } else { return; } } =head2 after_today This routine will validate the date and make sure it is greater than or equal to today (using C<< DateTime->today() >>). It takes only one param, which is the L format for the date being validated. If it validates and you tell D::FV to untaint this parameter it will be converted into a DateTime object. # make sure the project isn't already due my $profile = { required => [qw(death_date)], constraint_methods => { death_date => after_today('%m/%d/%Y'), }, untaint_all_constraints => 1, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub after_today { my $format = shift; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); return match_after_today($dfv, $format); }; } sub match_after_today { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # get the DateTime my $dt = _get_datetime_from_strp($value, $format); my $dt_target = DateTime->today(); # if we have valid DateTime objects and they have the correct # temporaral relationship if( $dt && $dt_target && $dt >= $dt_target ) { return $dt; } else { return; } } =head2 ymd_before_today This routine will validate the date and make sure it less than or equal to today (using C<< DateTime->today >>). It works just like L in the parameters it takes. If it validates and you tell D::FV to untaint this parameter it will be converted into a DateTime object. # make sure they weren't born in the future my $profile = { required => [qw(birth_date)], constraint_methods => { birth_date => ymd_before_today(qw(dob_year dob_month dob_day)), }, untaint_all_constraints => 1, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub ymd_before_today { my ($year, $month, $day, $hour, $min, $sec) = @_; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); my $data = $dfv->get_input_data(as_hashref => 1); return match_ymd_before_today( $dfv, _get_value($year, $data), _get_value($month, $data), _get_value($day, $data), _get_value($hour, $data), _get_value($min, $data), _get_value($sec, $data), ); }; } sub match_ymd_before_today { my $dt = match_ymd_to_datetime(@_); if( $dt && ( $dt <= DateTime->today ) ) { return $dt; } return; # if we get here then it's false } =head2 ymd_after_today This routine will validate the date and make sure it greater than or equal to today (using C<< DateTime->today >>). It works just like L in the parameters it takes. If it validates and you tell D::FV to untaint this parameter it will be converted into a DateTime object. # make sure the project isn't already due my $profile = { required => [qw(due_date)], constraint_methods => { birth_date => ymd_after_today(qw(dob_year dob_month dob_day)), }, untaint_all_constraints => 1, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub ymd_after_today { my ($year, $month, $day, $hour, $min, $sec) = @_; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); my $data = $dfv->get_input_data(as_hashref => 1); return match_ymd_after_today( $dfv, _get_value($year, $data), _get_value($month, $data), _get_value($day, $data), _get_value($hour, $data), _get_value($min, $data), _get_value($sec, $data), ); }; } sub match_ymd_after_today { my $dt = match_ymd_to_datetime(@_); if( $dt && ( $dt >= DateTime->today ) ) { return $dt; } return; # if we get here then it's false } =head2 before_datetime This routine will validate the date and make sure it occurs before the specified date. It takes two params: =over =item * first, the L format (for both the date we are validating and also the date we want to compare against) =item * second, the date we are comparing against. This date we are comparing against can either be a specified date (using a scalar ref), or a named parameter from your form (using a scalar name). =back If it validates and you tell D::FV to untaint this parameter it will be converted into a DateTime object. # make sure they were born before 1979 my $profile = { required => [qw(birth_date)], constraint_methods => { birth_date => before_datetime('%m/%d/%Y', '01/01/1979'), }, untaint_all_constraints => 1, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub before_datetime { my ($format, $date) = @_; # dereference stuff if we need to $date = $$date if( ref $date eq 'SCALAR' ); return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); # are we using a real date or the name of a parameter my $data = $dfv->get_input_data(as_hashref => 1); $date = $data->{$date} if( $data->{$date} ); return match_before_datetime($dfv, $format, $date); }; } sub match_before_datetime { my ($dfv, $format, $target_date) = @_; $target_date = $$target_date if( ref $target_date eq 'SCALAR' ); # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # get the DateTime my $dt = _get_datetime_from_strp($value, $format); my $dt_target = _get_datetime_from_strp($target_date, $format); # if we have valid DateTime objects and they have the correct # temporaral relationship if( $dt && $dt_target && $dt < $dt_target ) { return $dt; } else { return; } } =head2 after_datetime This routine will validate the date and make sure it occurs after the specified date. It takes two params: =over =item * first, the L format (for both the date we are validating and also the date we want to compare against) =item * second, the date we are comparing against. This date we are comparing against can either be a specified date (using a scalar ref), or a named parameter from your form (using a scalar name). =back # make sure they died after they were born my $profile = { required => [qw(birth_date death_date)], constraint_methods => { death_date => after_datetime('%m/%d/%Y', 'birth_date'), }, untaint_all_constraints => 1, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub after_datetime { my ($format, $date) = @_; # dereference stuff if we need to $date = $$date if( ref $date eq 'SCALAR' ); return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); # are we using a real date or the name of a parameter my $data = $dfv->get_input_data(as_hashref => 1); $date = _get_value($date, $data); return match_after_datetime($dfv, $format, $date); }; } sub match_after_datetime { my ($dfv, $format, $target_date) = @_; $target_date = $$target_date if( ref $target_date eq 'SCALAR' ); # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # get the DateTime my $dt = _get_datetime_from_strp($value, $format); my $dt_target = _get_datetime_from_strp($target_date, $format); # if we have valid DateTime objects and they have the correct # temporaral relationship if( $dt && $dt_target && $dt > $dt_target ) { return $dt; } else { return; } } =head2 between_datetimes This routine will validate the date and make sure it occurs after the first specified date and before the second specified date. It takes three params: =over =item * first, the L format (for both the date we are validating and also the dates we want to compare against) =item * second, the first date we are comparing against. =item * third, the second date we are comparing against. This date (and the second) we are comparing against can either be a specified date (using a scalar ref), or a named parameter from your form (using a scalar name). =back # make sure they died after they were born my $profile = { required => [qw(birth_date death_date marriage_date)], constraint_methods => { marriage_date => between_datetimes('%m/%d/%Y', 'birth_date', 'death_date'), }, untaint_all_constraints => 1, }; If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub between_datetimes { my ($format, $target1, $target2) = @_; # dereference stuff if we need to $target1 = $$target1 if( ref $target1 eq 'SCALAR' ); $target2 = $$target2 if( ref $target2 eq 'SCALAR' ); return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); # are we using a real date or the name of a parameter my $data = $dfv->get_input_data(as_hashref => 1); $target1 = _get_value($target1, $data); $target2 = _get_value($target2, $data); return match_between_datetimes($dfv, $format, $target1, $target2); } } sub match_between_datetimes { my ($dfv, $format, $target1, $target2) = @_; $target1 = $$target1 if( ref $target1 eq 'SCALAR' ); $target2 = $$target2 if( ref $target2 eq 'SCALAR' ); # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # get the DateTime my $dt = _get_datetime_from_strp($value, $format); my $dt_target1 = _get_datetime_from_strp($target1, $format); my $dt_target2 = _get_datetime_from_strp($target2, $format); # if we have valid DateTime objects and they have the correct # temporaral relationship if( $dt && $dt_target1 && $dt_target2 && $dt > $dt_target1 && $dt < $dt_target2 ) { return $dt; } else { return; } } =head1 DATABASE RELATED VALIDATION ROUTINES =head2 to_mysql_datetime The routine will change the date string into a DATETIME datatype suitable for MySQL. If you don't provide a format parameter then this routine will just validate the data as a valid MySQL DATETIME datatype (using L). If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub to_mysql_datetime { my $format = shift; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); return match_to_mysql_datetime($dfv, $format); } } sub match_to_mysql_datetime { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # make sure they have DateTime::Format::MySQL eval { require DateTime::Format::MySQL; }; die "DateTime::Format::MySQL is required to use this routine" if( $@ ); my $dt; # if they gave us a format (through params as a scalar ref) # then translate the value if( $format ) { $dt = _get_datetime_from_strp($value, $format); # else there is no format, so just use parse_datetime } else { eval { $dt = DateTime::Format::MySQL->parse_datetime($value) }; } if( $dt ) { return DateTime::Format::MySQL->format_datetime($dt); } else { return undef; } } =head2 to_mysql_date The routine will change the date string into a DATE datatype suitable for MySQL. If you don't provide a format param then this routine will validate the data as a valid DATE datatype in MySQL (using L). If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub to_mysql_date { my $format = shift; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); return match_to_mysql_date($dfv, $format); }; } sub match_to_mysql_date { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # make sure they have DateTime::Format::MySQL eval { require DateTime::Format::MySQL; }; die "DateTime::Format::MySQL is required to use this routine" if( $@ ); my $dt; # if they gave us a format (through params as a scalar ref) # then translate the value if( $format ) { $dt = _get_datetime_from_strp($value, $format); # else there is no format, so just use parse_datetime } else { eval { $dt = DateTime::Format::MySQL->parse_date($value) }; } if( $dt ) { return DateTime::Format::MySQL->format_date($dt); } else { return undef; } } =head2 to_mysql_timestamp The routine will change the date string into a TIMESTAMP datatype suitable for MySQL. If you don't provide a format then the data will be validated as a MySQL TIMESTAMP datatype. If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub to_mysql_timestamp { my $format = shift; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); match_to_mysql_timestamp($dfv, $format); }; } sub match_to_mysql_timestamp { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; my $dt; # if they gave us a format (through params as a scalar ref) # then translate the value if( $format ) { $dt = _get_datetime_from_strp($value, $format); # else there is no format, so parse into a timestamp } else { # if it matches a timestamp format YYYYMMDDHHMMSS # but we're actually a little looser than that... we take # YYYY-MM-DD HH:MM:SS with any other potential separators if( $value =~ /(\d{4})\D*(\d{2})\D*(\d{2})\D*(\d{2})\D*(\d{2})\D*(\d{2})/ ) { eval { $dt = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, ); }; } } if( $dt ) { return $dt->ymd('') . $dt->hms(''); } else { return undef; } } =head2 to_pg_datetime The routine will change the date string into a DATETIME datatype suitable for PostgreSQL. If you don't provide a format then the data will validated as a DATETIME datatype in PostgresSQL (using L). If the value is untainted (using C or C, it will change the date string into a DateTime object. =cut sub to_pg_datetime { my $format = shift; return sub { my $dfv = shift; croak("Must be called using 'constraint_methods'!") unless( blessed $dfv && $dfv->isa('Data::FormValidator::Results') ); match_to_pg_datetime($dfv, $format); }; } sub match_to_pg_datetime { my ($dfv, $format) = @_; # if $dfv is a ref then we are called as 'constraint_method' # else as 'constaint' my $value = ref $dfv ? $dfv->get_current_constraint_value : $dfv; # make sure they have DateTime::Format::MySQL eval { require DateTime::Format::Pg; }; die "DateTime::Format::Pg is required to use this routine" if( $@ ); my $dt; # if they gave us a format (through params as a scalar ref) # then translate the value if( $format ) { $dt = _get_datetime_from_strp($value, $format); # else there is no format, so just use parse_datetime } else { eval { $dt = DateTime::Format::Pg->parse_datetime($value) }; } if( $dt ) { return DateTime::Format::Pg->format_datetime($dt); } else { return undef; } } =head1 AUTHOR Michael Peters Thanks to Plus Three, LP (http://www.plusthree.com) for sponsoring my work on this module =head1 CONTRIBUTORS =over =item Mark Stosberg =item Charles Frank =item Aaron Ross =back =head1 SUPPORT This module is a part of the larger L project. If you have questions, comments, bug reports or feature requests, please join the L's mailing list. =head1 CAVEAT When passing parameters to typical L constraints you pass plain scalars to refer to query params and scalar-refs to refer to literals. We get around that in this module by assuming everything could be refering to a query param, and if one is not found, then it's a literal. This works well unless you have query params with names like C<'01/02/2005'> or C<'%m/%d/%Y'>. And if you do, shame on you for having such horrible names. =head1 SEE ALSO L, L. L, L, L =head1 COPYRIGHT & LICENSE Copyright Michael Peters 2010, all rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.