line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: State Directive for Validation Class Field Definitions |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Directive::State; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
53333
|
use strict; |
|
109
|
|
|
|
|
6295
|
|
|
109
|
|
|
|
|
3759
|
|
6
|
109
|
|
|
109
|
|
710
|
use warnings; |
|
109
|
|
|
|
|
273
|
|
|
109
|
|
|
|
|
2985
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
622
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
236
|
|
|
109
|
|
|
|
|
10659
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
835
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
276
|
|
|
109
|
|
|
|
|
1672
|
|
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 is not a valid state'; |
19
|
|
|
|
|
|
|
has 'regexp' => sub {sprintf'^(%s)$',join'|',map{quotemeta}@{shift->states}}; |
20
|
|
|
|
|
|
|
has 'states' => sub {[ # u.s. states and territories |
21
|
|
|
|
|
|
|
'Alabama', |
22
|
|
|
|
|
|
|
'Alaska', |
23
|
|
|
|
|
|
|
'Arizona', |
24
|
|
|
|
|
|
|
'Arkansas', |
25
|
|
|
|
|
|
|
'California', |
26
|
|
|
|
|
|
|
'Colorado', |
27
|
|
|
|
|
|
|
'Connecticut', |
28
|
|
|
|
|
|
|
'Delaware', |
29
|
|
|
|
|
|
|
'Florida', |
30
|
|
|
|
|
|
|
'Georgia', |
31
|
|
|
|
|
|
|
'Hawaii', |
32
|
|
|
|
|
|
|
'Idaho', |
33
|
|
|
|
|
|
|
'Illinois', |
34
|
|
|
|
|
|
|
'Indiana', |
35
|
|
|
|
|
|
|
'Iowa', |
36
|
|
|
|
|
|
|
'Kansas', |
37
|
|
|
|
|
|
|
'Kentucky', |
38
|
|
|
|
|
|
|
'Louisiana', |
39
|
|
|
|
|
|
|
'Maine', |
40
|
|
|
|
|
|
|
'Maryland', |
41
|
|
|
|
|
|
|
'Massachusetts', |
42
|
|
|
|
|
|
|
'Michigan', |
43
|
|
|
|
|
|
|
'Minnesota', |
44
|
|
|
|
|
|
|
'Mississippi', |
45
|
|
|
|
|
|
|
'Missouri', |
46
|
|
|
|
|
|
|
'Montana', |
47
|
|
|
|
|
|
|
'Nebraska', |
48
|
|
|
|
|
|
|
'Nevada', |
49
|
|
|
|
|
|
|
'New Hampshire', |
50
|
|
|
|
|
|
|
'New Jersey', |
51
|
|
|
|
|
|
|
'New Mexico', |
52
|
|
|
|
|
|
|
'New York', |
53
|
|
|
|
|
|
|
'North Carolina', |
54
|
|
|
|
|
|
|
'North Dakota', |
55
|
|
|
|
|
|
|
'Ohio', |
56
|
|
|
|
|
|
|
'Oklahoma', |
57
|
|
|
|
|
|
|
'Oregon', |
58
|
|
|
|
|
|
|
'Pennsylvania', |
59
|
|
|
|
|
|
|
'Rhode Island', |
60
|
|
|
|
|
|
|
'South Carolina', |
61
|
|
|
|
|
|
|
'South Dakota', |
62
|
|
|
|
|
|
|
'Tennessee', |
63
|
|
|
|
|
|
|
'Texas', |
64
|
|
|
|
|
|
|
'Utah', |
65
|
|
|
|
|
|
|
'Vermont', |
66
|
|
|
|
|
|
|
'Virginia', |
67
|
|
|
|
|
|
|
'Washington', |
68
|
|
|
|
|
|
|
'West Virginia', |
69
|
|
|
|
|
|
|
'Wisconsin', |
70
|
|
|
|
|
|
|
'Wyoming', |
71
|
|
|
|
|
|
|
'District of Columbia', |
72
|
|
|
|
|
|
|
'Puerto Rico', |
73
|
|
|
|
|
|
|
'Guam', |
74
|
|
|
|
|
|
|
'American Samoa', |
75
|
|
|
|
|
|
|
'U.S. Virgin Islands', |
76
|
|
|
|
|
|
|
'Northern Mariana Islands', |
77
|
|
|
|
|
|
|
]}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub validate { |
80
|
|
|
|
|
|
|
|
81
|
46
|
|
|
46
|
0
|
137
|
my ($self, $proto, $field, $param) = @_; |
82
|
|
|
|
|
|
|
|
83
|
46
|
50
|
33
|
|
|
288
|
if (defined $field->{state} && defined $param) { |
84
|
|
|
|
|
|
|
|
85
|
46
|
50
|
33
|
|
|
190
|
if ($field->{required} || $param) { |
86
|
|
|
|
|
|
|
|
87
|
46
|
|
|
|
|
92
|
my $type = $field->{state}; |
88
|
46
|
|
|
|
|
149
|
my $lre = $self->regexp; |
89
|
|
|
|
|
|
|
|
90
|
46
|
|
|
|
|
1637
|
my $sre = { |
91
|
|
|
|
|
|
|
'abbr' => qr/^(A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$/i, |
92
|
|
|
|
|
|
|
'long' => qr/$lre/i, |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
46
|
|
|
|
|
124
|
my $is_valid = 0; |
96
|
|
|
|
|
|
|
|
97
|
46
|
50
|
|
|
|
138
|
$type = isa_arrayref($type) ? $type : $type == 1 ? [keys %$sre] : [$type]; |
|
|
50
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
46
|
|
|
|
|
103
|
for (@{$type}) { |
|
46
|
|
|
|
|
108
|
|
100
|
|
|
|
|
|
|
|
101
|
78
|
100
|
|
|
|
616
|
if ($param =~ $sre->{$_}) { |
102
|
26
|
|
|
|
|
54
|
$is_valid = 1; |
103
|
26
|
|
|
|
|
51
|
last; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
46
|
100
|
|
|
|
248
|
$self->error($proto, $field) unless $is_valid; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
46
|
|
|
|
|
146
|
return $self; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |