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
|
|
53248
|
use strict; |
|
109
|
|
|
|
|
260
|
|
|
109
|
|
|
|
|
3351
|
|
6
|
109
|
|
|
109
|
|
625
|
use warnings; |
|
109
|
|
|
|
|
255
|
|
|
109
|
|
|
|
|
3013
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
573
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
239
|
|
|
109
|
|
|
|
|
11255
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
812
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
354
|
|
|
109
|
|
|
|
|
710
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '7.900059'; # 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
|
93
|
my ($self, $proto, $field, $param) = @_; |
23
|
|
|
|
|
|
|
|
24
|
32
|
50
|
33
|
|
|
147
|
if (defined $field->{time} && defined $param) { |
25
|
|
|
|
|
|
|
|
26
|
32
|
50
|
33
|
|
|
108
|
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
|
|
|
|
|
125
|
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
|
|
|
|
341
|
$self->error($proto, $field) unless $param =~ $tre; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
32
|
|
|
|
|
99
|
return $self; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |