line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::CountyStateProvince::US; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
294565
|
use warnings; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
34
|
|
5
|
2
|
|
|
2
|
|
633
|
use Locale::SubCountry; |
|
2
|
|
|
|
|
139633
|
|
|
2
|
|
|
|
|
31
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); |
8
|
2
|
|
|
2
|
|
746
|
use base 'CGI::Untaint::object'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
792
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince::US - Add U.S. states to CGI::Untaint::CountyStateProvince tables |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.03 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Adds a list of U.S. states to the list of counties/state/provinces |
25
|
|
|
|
|
|
|
which are known by the CGI::Untaint::CountyStateProvince validator allowing you |
26
|
|
|
|
|
|
|
to verify that a field in an HTML form contains a valid U.S. state. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
You must include CGI::Untaint::CountyStateProvince::US after including |
29
|
|
|
|
|
|
|
CGI::Untaint, otherwise it won't work. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use CGI::Info; |
32
|
|
|
|
|
|
|
use CGI::Untaint; |
33
|
|
|
|
|
|
|
use CGI::Untaint::CountyStateProvince::US; |
34
|
|
|
|
|
|
|
my $info = CGI::Info->new(); |
35
|
|
|
|
|
|
|
my $u = CGI::Untaint->new($info->params()); |
36
|
|
|
|
|
|
|
# Succeeds if state = 'MD' or 'Maryland', fails if state = 'Queensland'; |
37
|
|
|
|
|
|
|
$u->extract(-as_CountyStateProvince => 'state'); |
38
|
|
|
|
|
|
|
# ... |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SUBSOUTINES/METHODS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 is_valid |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Validates the data, setting the data to be the two letter abbreviation for the |
47
|
|
|
|
|
|
|
given state. See CGI::Untaint::is_valid. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub is_valid { |
52
|
6
|
|
|
6
|
1
|
19
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
|
|
11
|
my $value = uc($self->value); |
55
|
|
|
|
|
|
|
|
56
|
6
|
100
|
|
|
|
22
|
if($value =~ /([A-Z][A-Z\s]+)/) { |
57
|
5
|
|
|
|
|
14
|
$value = $1; |
58
|
|
|
|
|
|
|
} else { |
59
|
1
|
|
|
|
|
3
|
return 0; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
5
|
100
|
|
|
|
14
|
unless($self->{_validator}) { |
63
|
1
|
|
|
|
|
7
|
$self->{_validator} = Locale::SubCountry->new('US'); |
64
|
1
|
50
|
|
|
|
36
|
unless($self->{_validator}) { |
65
|
0
|
|
|
|
|
0
|
return 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
17
|
my $state = $self->{_validator}->code($value); |
70
|
5
|
100
|
66
|
|
|
1008
|
if($state && ($state ne 'unknown')) { |
71
|
|
|
|
|
|
|
# Given full state name |
72
|
|
|
|
|
|
|
# Detaintify |
73
|
1
|
50
|
|
|
|
5
|
if($state =~ /(^[A-Z]{2}$)/) { |
74
|
1
|
|
|
|
|
4
|
return $1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
10
|
$state = $self->{_validator}->full_name($value); |
79
|
4
|
100
|
66
|
|
|
111
|
if($state && ($state ne 'unknown')) { |
80
|
|
|
|
|
|
|
# Given two letter abbreviation |
81
|
2
|
|
|
|
|
15
|
return $value; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
6
|
return 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 value |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Sets the raw data which is to be validated. Called by the superclass, you |
90
|
|
|
|
|
|
|
are unlikely to want to call it. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub value { |
95
|
12
|
|
|
12
|
1
|
4083
|
my ($self, $value) = @_; |
96
|
|
|
|
|
|
|
|
97
|
12
|
100
|
|
|
|
27
|
if(defined($value)) { |
98
|
6
|
|
|
|
|
14
|
$self->{value} = $value; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
12
|
|
|
|
|
27
|
return $self->{value}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
BEGIN { |
105
|
2
|
|
|
2
|
|
1030
|
my $us = CGI::Untaint::CountyStateProvince::US->_new(); |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
66
|
push @CGI::Untaint::CountyStateProvince::countries, $us; |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 BUGS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Only two letter abbreviations are allowable, so 'Mass' won't work for |
117
|
|
|
|
|
|
|
Massachusetts. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
120
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
121
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince, CGI::Untaint |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SUPPORT |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
perldoc CGI::Untaint::CountyStateProvince::US |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
You can also look for information at: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * CPAN Ratings |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * Search CPAN |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright 2012 Nigel Horne. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is released under the following licence: GPL |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; # End of CGI::Untaint::CountyStateProvince::US |