line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::CountyStateProvince::GB; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
359063
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
111
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
102
|
|
5
|
3
|
|
|
3
|
|
3520
|
use Locale::SubCountry; |
|
3
|
|
|
|
|
862919
|
|
|
3
|
|
|
|
|
155
|
|
6
|
3
|
|
|
3
|
|
189
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
325
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); |
9
|
3
|
|
|
3
|
|
20
|
use base 'CGI::Untaint::object'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3664
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince::GB - Add British counties to CGI::Untaint::CountyStateProvince tables |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.11 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our %counties = ( |
24
|
|
|
|
|
|
|
'aberdeenshire' => 1, |
25
|
|
|
|
|
|
|
'anglesey' => 1, |
26
|
|
|
|
|
|
|
'angus' => 1, |
27
|
|
|
|
|
|
|
'avon' => 1, |
28
|
|
|
|
|
|
|
'ayrshire' => 1, |
29
|
|
|
|
|
|
|
'bedfordshire' => 1, |
30
|
|
|
|
|
|
|
'berkshire' => 1, |
31
|
|
|
|
|
|
|
'blaenau gwent' => 1, |
32
|
|
|
|
|
|
|
'brecknockshire' => 1, |
33
|
|
|
|
|
|
|
'bridgend' => 1, |
34
|
|
|
|
|
|
|
'buckinghamshire' => 1, |
35
|
|
|
|
|
|
|
'borders' => 1, |
36
|
|
|
|
|
|
|
'cardinganshire' => 1, |
37
|
|
|
|
|
|
|
'caerphilly' => 1, |
38
|
|
|
|
|
|
|
'cambridgeshire' => 1, |
39
|
|
|
|
|
|
|
'cardiff' => 1, |
40
|
|
|
|
|
|
|
'carmarthenshire' => 1, |
41
|
|
|
|
|
|
|
'ceredigion' => 1, |
42
|
|
|
|
|
|
|
'channel islands' => 1, |
43
|
|
|
|
|
|
|
'cheshire' => 1, |
44
|
|
|
|
|
|
|
'clackmannanshire' => 1, |
45
|
|
|
|
|
|
|
'clywd' => 1, |
46
|
|
|
|
|
|
|
'county durham' => 1, |
47
|
|
|
|
|
|
|
'county tyrone' => 1, |
48
|
|
|
|
|
|
|
'conwy' => 1, |
49
|
|
|
|
|
|
|
'cornwall' => 1, |
50
|
|
|
|
|
|
|
'cumbria' => 1, |
51
|
|
|
|
|
|
|
'derbyshire' => 1, |
52
|
|
|
|
|
|
|
'denbighshire' => 1, |
53
|
|
|
|
|
|
|
'devon' => 1, |
54
|
|
|
|
|
|
|
'dorset' => 1, |
55
|
|
|
|
|
|
|
'dumfries and galloway' => 1, |
56
|
|
|
|
|
|
|
'dyfed' => 1, |
57
|
|
|
|
|
|
|
'east lothian' => 1, |
58
|
|
|
|
|
|
|
'east sussex' => 1, |
59
|
|
|
|
|
|
|
'east yorkshire' => 1, |
60
|
|
|
|
|
|
|
'essex' => 1, |
61
|
|
|
|
|
|
|
'fife' => 1, |
62
|
|
|
|
|
|
|
'flintshire' => 1, |
63
|
|
|
|
|
|
|
'glamorgan' => 1, |
64
|
|
|
|
|
|
|
'gloucestershire' => 1, |
65
|
|
|
|
|
|
|
'grampian' => 1, |
66
|
|
|
|
|
|
|
'gwent' => 1, |
67
|
|
|
|
|
|
|
'gwynedd' => 1, |
68
|
|
|
|
|
|
|
'hampshire' => 1, |
69
|
|
|
|
|
|
|
'hertfordshire' => 1, |
70
|
|
|
|
|
|
|
'herefordshire' => 1, |
71
|
|
|
|
|
|
|
'isle of man' => 1, |
72
|
|
|
|
|
|
|
'isle of wight' => 1, |
73
|
|
|
|
|
|
|
'kent' => 1, |
74
|
|
|
|
|
|
|
'lancashire' => 1, |
75
|
|
|
|
|
|
|
'leicestershire' => 1, |
76
|
|
|
|
|
|
|
'lincolnshire' => 1, |
77
|
|
|
|
|
|
|
'london' => 1, |
78
|
|
|
|
|
|
|
'manchester' => 1, |
79
|
|
|
|
|
|
|
'merioneth' => 1, |
80
|
|
|
|
|
|
|
'merseyside' => 1, |
81
|
|
|
|
|
|
|
'mid lothian' => 1, |
82
|
|
|
|
|
|
|
'middlesex' => 1, # Doesn't exist anymore, but people like it |
83
|
|
|
|
|
|
|
'monmouthshire' => 1, |
84
|
|
|
|
|
|
|
'montgomeryshire' => 1, |
85
|
|
|
|
|
|
|
'north yorkshire' => 1, |
86
|
|
|
|
|
|
|
'norfolk' => 1, |
87
|
|
|
|
|
|
|
'northamptonshire' => 1, |
88
|
|
|
|
|
|
|
'northern ireland' => 1, |
89
|
|
|
|
|
|
|
'northumberland' => 1, |
90
|
|
|
|
|
|
|
'nottinghamshire' => 1, |
91
|
|
|
|
|
|
|
'oxfordshire' => 1, |
92
|
|
|
|
|
|
|
'pembrokeshire' => 1, |
93
|
|
|
|
|
|
|
'powys' => 1, |
94
|
|
|
|
|
|
|
'radnorshire' => 1, |
95
|
|
|
|
|
|
|
'renfrewshire' => 1, |
96
|
|
|
|
|
|
|
'shropshire' => 1, |
97
|
|
|
|
|
|
|
'somerset' => 1, |
98
|
|
|
|
|
|
|
'south yorkshire' => 1, |
99
|
|
|
|
|
|
|
'staffordshire' => 1, |
100
|
|
|
|
|
|
|
'strathclyde' => 1, |
101
|
|
|
|
|
|
|
'suffolk' => 1, |
102
|
|
|
|
|
|
|
'surrey' => 1, |
103
|
|
|
|
|
|
|
'tayside' => 1, |
104
|
|
|
|
|
|
|
'teesside' => 1, |
105
|
|
|
|
|
|
|
'tyne and wear' => 1, |
106
|
|
|
|
|
|
|
'warwickshire' => 1, |
107
|
|
|
|
|
|
|
'west dunbartonshire' => 1, |
108
|
|
|
|
|
|
|
'west lothian' => 1, |
109
|
|
|
|
|
|
|
'west midlands' => 1, |
110
|
|
|
|
|
|
|
'west sussex' => 1, |
111
|
|
|
|
|
|
|
'west yorkshire' => 1, |
112
|
|
|
|
|
|
|
'wiltshire' => 1, |
113
|
|
|
|
|
|
|
'worcestershire' => 1, |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
our %abbreviations = ( |
117
|
|
|
|
|
|
|
'beds' => 'bedfordshire', |
118
|
|
|
|
|
|
|
'cambs' => 'cambridgeshire', |
119
|
|
|
|
|
|
|
'cleveland' => 'teesside', |
120
|
|
|
|
|
|
|
'co durham' => 'county durham', |
121
|
|
|
|
|
|
|
'durham' => 'county durham', |
122
|
|
|
|
|
|
|
'east yorks' => 'east yorkshire', |
123
|
|
|
|
|
|
|
'glasgow' => 'west lothian', |
124
|
|
|
|
|
|
|
'gloucester' => 'gloucestershire', |
125
|
|
|
|
|
|
|
'greater london' => 'london', |
126
|
|
|
|
|
|
|
'hants' => 'hampshire', |
127
|
|
|
|
|
|
|
'herts' => 'hertfordshire', |
128
|
|
|
|
|
|
|
'lancs' => 'lancashire', |
129
|
|
|
|
|
|
|
'middx' => 'middlesex', |
130
|
|
|
|
|
|
|
'n yorkshire' => 'north yorkshire', |
131
|
|
|
|
|
|
|
'northants' => 'northamptonshire', |
132
|
|
|
|
|
|
|
'notts' => 'nottinghamshire', |
133
|
|
|
|
|
|
|
'oxon' => 'oxfordshire', |
134
|
|
|
|
|
|
|
'greater manchester' => 'manchester', |
135
|
|
|
|
|
|
|
's yorkshire' => 'south yorkshire', |
136
|
|
|
|
|
|
|
'westmidlands' => 'west midlands', |
137
|
|
|
|
|
|
|
'west mids' => 'west midlands', |
138
|
|
|
|
|
|
|
'west yorks' => 'west yorkshire', |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SYNOPSIS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Adds a list of British counties to the list of counties/state/provinces |
144
|
|
|
|
|
|
|
which are known by the CGI::Untaint::CountyStateProvince validator so that |
145
|
|
|
|
|
|
|
an HTML form sent by CGI contains a valid county. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
You must include CGI::Untaint::CountyStateProvince::GB after including |
148
|
|
|
|
|
|
|
CGI::Untaint, otherwise it won't work. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
use CGI::Info; |
151
|
|
|
|
|
|
|
use CGI::Untaint; |
152
|
|
|
|
|
|
|
use CGI::Untaint::CountyStateProvince::GB; |
153
|
|
|
|
|
|
|
my $info = CGI::Info->new(); |
154
|
|
|
|
|
|
|
my $u = CGI::Untaint->new($info->params()); |
155
|
|
|
|
|
|
|
# Succeeds if state = 'Kent', fails if state = 'Queensland'; |
156
|
|
|
|
|
|
|
$u->extract(-as_CountyStateProvince => 'state'); |
157
|
|
|
|
|
|
|
# ... |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SUBSOUTINES/METHODS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 is_valid |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Validates the data. See CGI::Untaint::is_valid. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub is_valid { |
170
|
8
|
|
|
8
|
1
|
33
|
my $self = shift; |
171
|
|
|
|
|
|
|
|
172
|
8
|
|
|
|
|
17
|
my $value = lc($self->value); |
173
|
|
|
|
|
|
|
|
174
|
8
|
50
|
|
|
|
39
|
if($value =~ /([a-z\s]+)/) { |
175
|
8
|
|
|
|
|
22
|
$value = $1; |
176
|
|
|
|
|
|
|
} else { |
177
|
0
|
|
|
|
|
0
|
return 0; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
8
|
100
|
|
|
|
29
|
if(exists($abbreviations{$value})) { |
181
|
4
|
|
|
|
|
19
|
return $abbreviations{$value}; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Try using Locale::SubCountry first, but be aware of RT77735 - some |
185
|
|
|
|
|
|
|
# counties are missing and some towns are listed as counties. |
186
|
4
|
100
|
|
|
|
16
|
unless($self->{_validator}) { |
187
|
1
|
|
|
|
|
14
|
$self->{_validator} = Locale::SubCountry->new('GB'); |
188
|
1
|
50
|
|
|
|
47
|
unless($self->{_validator}) { |
189
|
0
|
|
|
|
|
0
|
carp 'Can\'t instantiate Locale::SubCountry'; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
4
|
|
|
|
|
21
|
my $county = $self->{_validator}->code($value); |
194
|
4
|
100
|
66
|
|
|
5200
|
if($county && ($county ne 'unknown')) { |
195
|
1
|
|
|
|
|
6
|
return $value; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
3
|
100
|
|
|
|
24
|
return exists($counties{$value}) ? $value : 0; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 value |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Sets the raw data which is to be validated. Called by the superclass, you |
204
|
|
|
|
|
|
|
are unlikely to want to call it. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub value { |
209
|
16
|
|
|
16
|
1
|
10279
|
my ($self, $value) = @_; |
210
|
|
|
|
|
|
|
|
211
|
16
|
100
|
|
|
|
43
|
if(defined($value)) { |
212
|
8
|
|
|
|
|
25
|
$self->{value} = $value; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
16
|
|
|
|
|
47
|
return $self->{value}; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
BEGIN { |
219
|
3
|
|
|
3
|
|
3025
|
my $gb = CGI::Untaint::CountyStateProvince::GB->_new(); |
220
|
|
|
|
|
|
|
|
221
|
3
|
|
|
|
|
171
|
push @CGI::Untaint::CountyStateProvince::countries, $gb; |
222
|
|
|
|
|
|
|
}; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 AUTHOR |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 BUGS |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
231
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
232
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 SEE ALSO |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince, CGI::Untaint |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 SUPPORT |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
perldoc CGI::Untaint::CountyStateProvince::GB |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
You can also look for information at: |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=over 4 |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
L |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item * CPAN Ratings |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
L |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item * Search CPAN |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
L |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=back |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Copyright 2012 Nigel Horne. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
This program is released under the following licence: GPL |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; # End of CGI::Untaint::CountyStateProvince::GB |