line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Time Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::Time; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
43437
|
use strict; |
|
109
|
|
|
|
|
283
|
|
|
109
|
|
|
|
|
2735
|
|
6
|
109
|
|
|
109
|
|
484
|
use warnings; |
|
109
|
|
|
|
|
216
|
|
|
109
|
|
|
|
|
2366
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
482
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
193
|
|
|
109
|
|
|
|
|
8577
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
639
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
215
|
|
|
109
|
|
|
|
|
623
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900058'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'mixin' => 1; |
16
|
|
|
|
|
|
|
has 'field' => 1; |
17
|
|
|
|
|
|
|
has 'multi' => 0; |
18
|
|
|
|
|
|
|
has 'message' => '%s requires a valid time'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub validate { |
21
|
|
|
|
|
|
|
|
22
|
32
|
|
|
32
|
0
|
56
|
my ($self, $proto, $field, $param) = @_; |
23
|
|
|
|
|
|
|
|
24
|
32
|
50
|
33
|
|
|
112
|
if (defined $field->{time} && defined $param) { |
25
|
|
|
|
|
|
|
|
26
|
32
|
50
|
33
|
|
|
90
|
if ($field->{required} || $param) { |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# determines if the param is a valid time |
29
|
|
|
|
|
|
|
# validates time as 24hr (HH:MM) or am/pm ([H]H:MM[a|p]m) |
30
|
|
|
|
|
|
|
# does not validate seconds |
31
|
|
|
|
|
|
|
|
32
|
32
|
|
|
|
|
97
|
my $tre = qr%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%; |
33
|
|
|
|
|
|
|
|
34
|
32
|
100
|
|
|
|
271
|
$self->error($proto, $field) unless $param =~ $tre; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
32
|
|
|
|
|
81
|
return $self; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |