line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::CountyStateProvince::US; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
403091
|
use warnings; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
67
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
39
|
|
5
|
2
|
|
|
2
|
|
1141
|
use Locale::SubCountry; |
|
2
|
|
|
|
|
187005
|
|
|
2
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); |
8
|
2
|
|
|
2
|
|
876
|
use base 'CGI::Untaint::object'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1257
|
|
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.04 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
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
|
28
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
|
|
15
|
my $value = uc($self->value); |
55
|
|
|
|
|
|
|
|
56
|
6
|
100
|
|
|
|
33
|
if($value =~ /([A-Z][A-Z\s]+)/) { |
57
|
5
|
|
|
|
|
15
|
$value = $1; |
58
|
|
|
|
|
|
|
} else { |
59
|
1
|
|
|
|
|
3
|
return 0; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
5
|
100
|
|
|
|
16
|
unless($self->{_validator}) { |
63
|
1
|
|
|
|
|
11
|
$self->{_validator} = Locale::SubCountry->new('US'); |
64
|
1
|
50
|
|
|
|
52
|
unless($self->{_validator}) { |
65
|
0
|
|
|
|
|
0
|
return 0; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
22
|
my $state = $self->{_validator}->code($value); |
70
|
5
|
100
|
66
|
|
|
1258
|
if($state && ($state ne 'unknown')) { |
71
|
|
|
|
|
|
|
# Given full state name |
72
|
|
|
|
|
|
|
# Detaintify |
73
|
1
|
50
|
|
|
|
8
|
if($state =~ /(^[A-Z]{2}$)/) { |
74
|
1
|
|
|
|
|
5
|
return $1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
31
|
$state = $self->{_validator}->full_name($value); |
79
|
4
|
100
|
66
|
|
|
145
|
if($state && ($state ne 'unknown')) { |
80
|
|
|
|
|
|
|
# Given two letter abbreviation |
81
|
2
|
|
|
|
|
22
|
return $value; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
7
|
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
|
5827
|
my ($self, $value) = @_; |
96
|
|
|
|
|
|
|
|
97
|
12
|
100
|
|
|
|
34
|
if(defined($value)) { |
98
|
6
|
|
|
|
|
18
|
$self->{value} = $value; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
12
|
|
|
|
|
98
|
return $self->{value}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
BEGIN { |
105
|
2
|
|
|
2
|
|
1263
|
my $us = CGI::Untaint::CountyStateProvince::US->_new(); |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
93
|
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 * CPAN Ratings |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * Search CPAN |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Copyright 2012-2019 Nigel Horne. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This program is released under the following licence: GPL2 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; # End of CGI::Untaint::CountyStateProvince::US |