line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::CountyStateProvince::US; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
79532
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
81
|
|
4
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
82
|
|
5
|
3
|
|
|
3
|
|
2856
|
use Locale::SubCountry; |
|
3
|
|
|
|
|
834870
|
|
|
3
|
|
|
|
|
148
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); |
8
|
3
|
|
|
3
|
|
190
|
use base 'CGI::Untaint::object'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3392
|
|
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.02 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
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 so that |
26
|
|
|
|
|
|
|
an HTML form sent by CGI 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
|
5
|
|
|
5
|
1
|
51
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
13
|
my $value = uc($self->value); |
55
|
|
|
|
|
|
|
|
56
|
5
|
50
|
|
|
|
28
|
if($value =~ /([A-Z\s]+)/) { |
57
|
5
|
|
|
|
|
13
|
$value = $1; |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
0
|
return 0; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
5
|
100
|
|
|
|
58
|
unless($self->{_validator}) { |
63
|
1
|
|
|
|
|
9
|
$self->{_validator} = Locale::SubCountry->new('US'); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
5
|
50
|
|
|
|
56
|
unless($self->{_validator}) { |
67
|
0
|
|
|
|
|
0
|
return 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
5
|
|
|
|
|
25
|
my $state = $self->{_validator}->code($value); |
71
|
5
|
100
|
66
|
|
|
2396
|
if($state && ($state ne 'unknown')) { |
72
|
|
|
|
|
|
|
# Detaintify |
73
|
1
|
50
|
|
|
|
8
|
if($state =~ /(^[A-Z]{2}$)/) { |
74
|
1
|
|
|
|
|
6
|
return $1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
19
|
$state = $self->{_validator}->full_name($value); |
79
|
4
|
100
|
66
|
|
|
146
|
if($state && ($state ne 'unknown')) { |
80
|
2
|
|
|
|
|
11
|
return $value; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
8
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 value |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Sets the raw data which is to be validated. Called by the superclass, you |
89
|
|
|
|
|
|
|
are unlikely to want to call it. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub value { |
94
|
10
|
|
|
10
|
1
|
6439
|
my ($self, $value) = @_; |
95
|
|
|
|
|
|
|
|
96
|
10
|
100
|
|
|
|
32
|
if(defined($value)) { |
97
|
5
|
|
|
|
|
15
|
$self->{value} = $value; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
10
|
|
|
|
|
30
|
return $self->{value}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
BEGIN { |
104
|
3
|
|
|
3
|
|
2194
|
my $gb = CGI::Untaint::CountyStateProvince::US->_new(); |
105
|
|
|
|
|
|
|
|
106
|
3
|
|
|
|
|
151
|
push @CGI::Untaint::CountyStateProvince::countries, $gb; |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 BUGS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Only two letter abbreviations are allowable, so 'Mass' won't work for |
116
|
|
|
|
|
|
|
Massachusetts. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
119
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
120
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SEE ALSO |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince, CGI::Untaint |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SUPPORT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
perldoc CGI::Untaint::CountyStateProvince::US |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
You can also look for information at: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * CPAN Ratings |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * Search CPAN |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright 2012 Nigel Horne. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This program is released under the following licence: GPL |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; # End of CGI::Untaint::CountyStateProvince::US |