line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::CountyStateProvince; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
248298
|
use warnings; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
73
|
|
4
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
75
|
|
5
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
116
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use base 'CGI::Untaint::object'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1002
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince - Validate a state, county or province in a |
12
|
|
|
|
|
|
|
CGI script. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.06 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @countries; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince is a subclass of CGI::Untaint used to |
27
|
|
|
|
|
|
|
validate if the given user data is a valid county/state/province. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This class is not to be instantiated, instead a subclass must be |
30
|
|
|
|
|
|
|
instantiated. For example L would |
31
|
|
|
|
|
|
|
validate against a British county, L |
32
|
|
|
|
|
|
|
would validate against a US state, and so on. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use CGI::Info; |
35
|
|
|
|
|
|
|
use CGI::Untaint; |
36
|
|
|
|
|
|
|
use CGI::Untaint::CountyStateProvince; |
37
|
|
|
|
|
|
|
# ... |
38
|
|
|
|
|
|
|
my $info = CGI::Info->new(); |
39
|
|
|
|
|
|
|
my $params = $info->params(); |
40
|
|
|
|
|
|
|
# ... |
41
|
|
|
|
|
|
|
# Country table(s) must be loaded after CGI::Untaint::CountyStateProvince |
42
|
|
|
|
|
|
|
if($params->{'country'} == 44) { |
43
|
|
|
|
|
|
|
require CGI::Untaint::CountyStateProvince::GB; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince::GB->import(); |
46
|
|
|
|
|
|
|
} elsif($params->{'country'} == 1) { |
47
|
|
|
|
|
|
|
require CGI::Untaint::CountyStateProvince::US; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince::US->import(); |
50
|
|
|
|
|
|
|
} else { |
51
|
|
|
|
|
|
|
die 'Unsupported country ' . $params->{'country'}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
my $u = CGI::Untaint->new($params); |
54
|
|
|
|
|
|
|
my $csp = $u->extract(-as_CountyStateProvince => 'state'); |
55
|
|
|
|
|
|
|
# $csp will be lower case |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 is_valid |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Validates the data. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _untaint_re { |
66
|
|
|
|
|
|
|
# Only allow letters and spaces |
67
|
7
|
|
|
7
|
|
7393
|
return qr/^([a-zA-z\s]+)$/; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub is_valid { |
71
|
3
|
|
|
3
|
1
|
63
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
3
|
50
|
|
|
|
9
|
unless(scalar(@countries) > 0) { |
74
|
3
|
|
|
|
|
53
|
carp "You must specify at least one country"; |
75
|
3
|
|
|
|
|
860
|
return 0; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $value = $self->value; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
foreach my $country (@countries) { |
81
|
0
|
|
|
|
|
|
$country->value($value); |
82
|
0
|
|
|
|
|
|
my $new_value = $country->is_valid(); |
83
|
0
|
0
|
|
|
|
|
if($new_value) { |
84
|
0
|
0
|
|
|
|
|
if($new_value ne $value) { |
85
|
0
|
|
|
|
|
|
$self->value($new_value); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
|
return 0; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return 1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 BUGS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
102
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
103
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
CGI::Untaint |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SUPPORT |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
perldoc CGI::Untaint::CountyStateProvince |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
You can also look for information at: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=over 4 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * CPAN Ratings |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * Search CPAN |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=back |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Copyright 2012-2019 Nigel Horne. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This program is released under the following licence: GPL2 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; # End of CGI::Untaint::CountyStateProvince |