@ISA = qw(Exporter);
use Carp qw(confess);
-our $VERSION = "1.004";
+our $VERSION = "1.005";
my %built_ins =
(
maxdate => '+1d',
maxdatemsg => 'The date entered must be in the past',
},
+ time =>
+ {
+ time => 1,
+ },
integer =>
{
integer => 1,
}
}
}
+ if ($rule->{time}) {
+ require DevHelp::Date;
+ my $msg;
+ if (my ($hour, $min, $sec)
+ = DevHelp::Date::dh_parse_time($data, \$msg)) {
+ # nothing to do here yet, later it will allow limits
+ }
+ else {
+ $errors->{$field} =
+ _make_error($field, $info, $rule,
+ '$n is not a valid time of day');
+ last RULE;
+ }
+ }
if ($rule->{confirm}) {
my $other = $self->param($rule->{confirm});
unless ($other eq $data) {
if ($rule->{ref}) {
my $method = $rule->{method}
or confess "Missing method in ref rule $rule_name";
- unless ($rule->{ref}->$method($data)) {
+ my $before = $rule->{before};
+ my @before = defined $before ? ( ref $before ? @$before : split /,/, $before ) : ();
+ my $after = $rule->{after};
+ my @after = defined $after ? ( ref $after ? @$after : split /,/, $after ) : ();
+ unless ($rule->{ref}->$method(@before, $data, @after)) {
$errors->{$field} = _make_error($field, $info, $rule, 'No such $n');
last RULE;
}
=head1 DESCRIPTION
+Performs simple validation of CGI or hash data.
+
=head1 RULES PARAMETER
The rules parameter is a hash with 2 keys:
=item rules
A hash of rules. See the rules description under L<CONFIGURED
-VALIDATON>.
+VALIDATION>.
=back
id for internationlization of the field description and a default
field description, separated by commas.
-Each validation rule name has a corresponding section, [Validate Rule
-I<rule-name>], which describes the rule. Rule names can also refer to
-built-in rules,
+Each validation rule name has a corresponding section,C<< [Validation
+Rule I<rule-name>] >>, which describes the rule. Rule names can also
+refer to built-in rules,
Values in the validation rule section are:
days of week. Uses C<dowmsg> from the field or rule for the error
message.
+=item time
+
+If true, validates that the value can be parsed by
+L<DevHelp::Date/dh_parse_time()>.
+
=item confirm
Specify another field that the field must be equal to, intended for
if the result is true. This is intended for checking the existence of
objects in a collection.
+Optionally C<before> can be an array ref or comma-separated list of
+parameters to supply before the value.
+
+Optionally C<after> can be an array ref or comma-separated list of
+parameters to supply after the value.
+
=back
=head1 BUILT-IN RULES
A valid date in the future.
+=item time
+
+Parses as a time as per dh_parse_time().
+
=item integer
Any integer.
#!perl -w
use strict;
-use Test::More tests => 34;
+use Test::More tests => 38;
BEGIN { use_ok('DevHelp::Validate'); }
}
}
}
+
+# times
+{
+ my $val = DevHelp::Validate::Hash->new
+ (
+ fields =>
+ {
+ time => { rules => "time" },
+ }
+ );
+ my %errors;
+ ok($val->validate({time => "10:00"}, \%errors), "simple hh:mm");
+ ok($val->validate({time => "2pm" }, \%errors), "simple Hpm");
+ ok($val->validate({time => "12pm" }, \%errors), "simple 12pm");
+ ok(!$val->validate({time => "13pm" }, \%errors), "simple 13pm");
+}
site/cgi-bin/modules/DevHelp/Payments/SecurePayXML.pm Verbatim paragraph in NAME section 1
site/cgi-bin/modules/DevHelp/Payments/Test.pm =back without previous =over 1
site/cgi-bin/modules/DevHelp/Tags/Iterate.pm =item without previous =over 1
-site/cgi-bin/modules/DevHelp/Validate.pm empty section in previous paragraph 1
site/cgi-bin/modules/DevHelp/Validate.pm multiple occurrence of link target 'confirm' 1
site/cgi-bin/modules/DevHelp/Validate.pm multiple occurrence of link target 'date' 1
site/cgi-bin/modules/DevHelp/Validate.pm multiple occurrence of link target 'integer' 1
site/cgi-bin/modules/DevHelp/Validate.pm multiple occurrence of link target 'required' 1
site/cgi-bin/modules/DevHelp/Validate.pm multiple occurrence of link target 'rules' 1
-site/cgi-bin/modules/DevHelp/Validate.pm unresolved internal link 'CONFIGURED VALIDATON' 1
+site/cgi-bin/modules/DevHelp/Validate.pm multiple occurrence of link target 'time' 1
site/cgi-bin/modules/Generate.pm =item without previous =over 1
site/cgi-bin/modules/Generate.pm empty section in previous paragraph 1
site/cgi-bin/modules/Generate/Article.pm =item without previous =over 1