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