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
|
|
43913
|
use strict; |
|
109
|
|
|
|
|
5251
|
|
|
109
|
|
|
|
|
3174
|
|
6
|
109
|
|
|
109
|
|
576
|
use warnings; |
|
109
|
|
|
|
|
200
|
|
|
109
|
|
|
|
|
2492
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
475
|
use base 'Validation::Class::Directive'; |
|
109
|
|
|
|
|
226
|
|
|
109
|
|
|
|
|
9177
|
|
9
|
|
|
|
|
|
|
|
10
|
109
|
|
|
109
|
|
632
|
use Validation::Class::Util; |
|
109
|
|
|
|
|
226
|
|
|
109
|
|
|
|
|
1405
|
|
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 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
|
193
|
my ($self, $proto, $field, $param) = @_; |
82
|
|
|
|
|
|
|
|
83
|
46
|
50
|
33
|
|
|
384
|
if (defined $field->{state} && defined $param) { |
84
|
|
|
|
|
|
|
|
85
|
46
|
50
|
33
|
|
|
283
|
if ($field->{required} || $param) { |
86
|
|
|
|
|
|
|
|
87
|
46
|
|
|
|
|
120
|
my $type = $field->{state}; |
88
|
46
|
|
|
|
|
270
|
my $lre = $self->regexp; |
89
|
|
|
|
|
|
|
|
90
|
46
|
|
|
|
|
1738
|
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
|
|
|
|
|
138
|
my $is_valid = 0; |
96
|
|
|
|
|
|
|
|
97
|
46
|
50
|
|
|
|
245
|
$type = isa_arrayref($type) ? $type : $type == 1 ? [keys %$sre] : [$type]; |
|
|
50
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
46
|
|
|
|
|
120
|
for (@{$type}) { |
|
46
|
|
|
|
|
169
|
|
100
|
|
|
|
|
|
|
|
101
|
74
|
100
|
|
|
|
1060
|
if ($param =~ $sre->{$_}) { |
102
|
26
|
|
|
|
|
93
|
$is_valid = 1; |
103
|
26
|
|
|
|
|
71
|
last; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
46
|
100
|
|
|
|
412
|
$self->error($proto, $field) unless $is_valid; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
46
|
|
|
|
|
162
|
return $self; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |