line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::CountyStateProvince::GB; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
452506
|
use warnings; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
102
|
|
4
|
3
|
|
|
3
|
|
22
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
59
|
|
5
|
3
|
|
|
3
|
|
1631
|
use Locale::SubCountry; |
|
3
|
|
|
|
|
269127
|
|
|
3
|
|
|
|
|
465
|
|
6
|
3
|
|
|
3
|
|
881
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
297
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); |
9
|
3
|
|
|
3
|
|
21
|
use base 'CGI::Untaint::object'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1972
|
|
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.12 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
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
|
|
|
|
|
|
|
'bucks' => 'buckinghamshire', |
119
|
|
|
|
|
|
|
'cambs' => 'cambridgeshire', |
120
|
|
|
|
|
|
|
'cleveland' => 'teesside', |
121
|
|
|
|
|
|
|
'co durham' => 'county durham', |
122
|
|
|
|
|
|
|
'durham' => 'county durham', |
123
|
|
|
|
|
|
|
'east yorks' => 'east yorkshire', |
124
|
|
|
|
|
|
|
'glasgow' => 'west lothian', |
125
|
|
|
|
|
|
|
'gloucester' => 'gloucestershire', |
126
|
|
|
|
|
|
|
'great london' => 'london', |
127
|
|
|
|
|
|
|
'greater london' => 'london', |
128
|
|
|
|
|
|
|
'hants' => 'hampshire', |
129
|
|
|
|
|
|
|
'herts' => 'hertfordshire', |
130
|
|
|
|
|
|
|
'lancs' => 'lancashire', |
131
|
|
|
|
|
|
|
'lancs.' => 'lancashire', |
132
|
|
|
|
|
|
|
'Lancs.' => 'lancashire', |
133
|
|
|
|
|
|
|
'middx' => 'middlesex', |
134
|
|
|
|
|
|
|
'n yorkshire' => 'north yorkshire', |
135
|
|
|
|
|
|
|
'northants' => 'northamptonshire', |
136
|
|
|
|
|
|
|
'notts' => 'nottinghamshire', |
137
|
|
|
|
|
|
|
'oxon' => 'oxfordshire', |
138
|
|
|
|
|
|
|
'greater manchester' => 'manchester', |
139
|
|
|
|
|
|
|
's yorkshire' => 'south yorkshire', |
140
|
|
|
|
|
|
|
's glos' => 'gloucestershire', |
141
|
|
|
|
|
|
|
'south gloster' => 'gloucestershire', |
142
|
|
|
|
|
|
|
'vale of glamorgan' => 'glamorgan', |
143
|
|
|
|
|
|
|
'westmidlands' => 'west midlands', |
144
|
|
|
|
|
|
|
'west mids' => 'west midlands', |
145
|
|
|
|
|
|
|
'west yorks' => 'west yorkshire', |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SYNOPSIS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Adds a list of British counties to the list of counties/state/provinces |
151
|
|
|
|
|
|
|
which are known by the CGI::Untaint::CountyStateProvince validator so that |
152
|
|
|
|
|
|
|
an HTML form sent by CGI contains a valid county. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
You must include CGI::Untaint::CountyStateProvince::GB after including |
155
|
|
|
|
|
|
|
CGI::Untaint, otherwise it won't work. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
use CGI::Info; |
158
|
|
|
|
|
|
|
use CGI::Untaint; |
159
|
|
|
|
|
|
|
use CGI::Untaint::CountyStateProvince::GB; |
160
|
|
|
|
|
|
|
my $info = CGI::Info->new(); |
161
|
|
|
|
|
|
|
my $u = CGI::Untaint->new($info->params()); |
162
|
|
|
|
|
|
|
# Succeeds if state = 'Kent', fails if state = 'Queensland'; |
163
|
|
|
|
|
|
|
$u->extract(-as_CountyStateProvince => 'state'); |
164
|
|
|
|
|
|
|
# ... |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 SUBSOUTINES/METHODS |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 is_valid |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Validates the data. See CGI::Untaint::is_valid. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub is_valid { |
177
|
11
|
|
|
11
|
1
|
39
|
my $self = shift; |
178
|
|
|
|
|
|
|
|
179
|
11
|
|
|
|
|
24
|
my $value = lc($self->value); |
180
|
|
|
|
|
|
|
|
181
|
11
|
100
|
|
|
|
52
|
if($value =~ /([a-z][a-z\s]+)/) { |
182
|
10
|
|
|
|
|
36
|
$value = $1; |
183
|
|
|
|
|
|
|
} else { |
184
|
1
|
|
|
|
|
3
|
return 0; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
10
|
100
|
|
|
|
29
|
if(exists($abbreviations{$value})) { |
188
|
4
|
|
|
|
|
16
|
return $abbreviations{$value}; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Try using Locale::SubCountry first, but be aware of RT77735 - some |
192
|
|
|
|
|
|
|
# counties are missing and some towns are listed as counties. |
193
|
6
|
100
|
|
|
|
18
|
unless($self->{_validator}) { |
194
|
1
|
|
|
|
|
19
|
$self->{_validator} = Locale::SubCountry->new('GB'); |
195
|
1
|
50
|
|
|
|
48
|
unless($self->{_validator}) { |
196
|
0
|
|
|
|
|
0
|
carp 'Can\'t instantiate Locale::SubCountry'; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# my $county = $self->{_validator}->code($value); |
201
|
|
|
|
|
|
|
# if($county && ($county ne 'unknown')) { |
202
|
|
|
|
|
|
|
# return $value; |
203
|
|
|
|
|
|
|
# } |
204
|
|
|
|
|
|
|
|
205
|
6
|
100
|
|
|
|
25
|
return exists($counties{$value}) ? $value : 0; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 value |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Sets the raw data which is to be validated. Called by the superclass, you |
211
|
|
|
|
|
|
|
are unlikely to want to call it. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub value { |
216
|
22
|
|
|
22
|
1
|
7209
|
my ($self, $value) = @_; |
217
|
|
|
|
|
|
|
|
218
|
22
|
100
|
|
|
|
56
|
if(defined($value)) { |
219
|
11
|
|
|
|
|
29
|
$self->{value} = $value; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
22
|
|
|
|
|
59
|
return $self->{value}; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
BEGIN { |
226
|
3
|
|
|
3
|
|
2333
|
my $gb = CGI::Untaint::CountyStateProvince::GB->_new(); |
227
|
|
|
|
|
|
|
|
228
|
3
|
|
|
|
|
178
|
push @CGI::Untaint::CountyStateProvince::countries, $gb; |
229
|
|
|
|
|
|
|
}; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 AUTHOR |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 BUGS |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
238
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
239
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 SEE ALSO |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
CGI::Untaint::CountyStateProvince, CGI::Untaint |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 SUPPORT |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
perldoc CGI::Untaint::CountyStateProvince::GB |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
You can also look for information at: |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=over 4 |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
L |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item * CPAN Ratings |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
L |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item * Search CPAN |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
L |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=back |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Copyright 2012-19 Nigel Horne. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This program is released under the following licence: GPL2 |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=cut |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
1; # End of CGI::Untaint::CountyStateProvince::GB |