| 1 | package CGI::Untaint::CountyStateProvince::GB; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Locale::SubCountry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); | ||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use base 'CGI::Untaint::object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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.13 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | 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 | 4 | 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/states/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 | |||||||||||||||||||||||||||||
| 161 | my $info = CGI::Info->new(); | ||||||||||||||||||||||||||||
| 162 | my $u = CGI::Untaint->new($info->params()); | ||||||||||||||||||||||||||||
| 163 | # Succeeds if state = 'Kent', fails if state = 'Queensland'; | ||||||||||||||||||||||||||||
| 164 | $u->extract(-as_CountyStateProvince => 'state'); | ||||||||||||||||||||||||||||
| 165 | # ... | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 is_valid | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Validates the data. See CGI::Untaint::is_valid. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 28 | ▶ | sub is_valid { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 28 | my $self = shift; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 28 | my $value = lc($self->value()); | |||||||||||||||||||||||||||
| 181 | 28 | $value =~ s/^\s+|\s+$//g; # Trim whitespace | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 28 | ▶ | if($value =~ /([a-z][a-z\s]+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 26 | $value = $1; | |||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||
| 186 | 2 | return 0; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 26 | ▶ | if(exists($abbreviations{$value})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 10 | return $abbreviations{$value}; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # Attempt Locale::SubCountry validation | ||||||||||||||||||||||||||||
| 194 | # Be aware of RT77735 - some | ||||||||||||||||||||||||||||
| 195 | # counties are missing and some towns and unitary authorities are listed as counties | ||||||||||||||||||||||||||||
| 196 | 16 | ▶ | my $validator = $self->{_validator} ||= Locale::SubCountry->new('GB'); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_validator"} ||= "Locale::SubCountry"->new("GB")
MC/DC0%0/2
$self->{"_validator"} ||= "Locale::SubCountry"->new("GB")
$self->{"_validator"}
"Locale::SubCountry"->new("GB")
Truth table66%2/3
A ||= B
A= $self->{"_validator"}B= "Locale::SubCountry"->new("GB")
| |||||||||||||||||||||||||||||
| 197 | 16 | ▶ | if($validator && (my $region_code = $validator->code($value))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$validator and my $region_code = $validator->code($value)
MC/DC0%0/2
$validator and my $region_code = $validator->code($value)
$validator
my $region_code = $validator->code($value)
Truth table33%1/3
A and B
A= $validatorB= my $region_code = $validator->code($value)
| |||||||||||||||||||||||||||||
| 198 | 16 | ▶ | return $value if($region_code ne 'unknown'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 10 | ▶ | return exists($counties{$value}) ? $value : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =head2 value | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | Sets the raw data to be validated. | ||||||||||||||||||||||||||||
| 207 | Called by the superclass, | ||||||||||||||||||||||||||||
| 208 | you are unlikely to want to call it. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =cut | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 56 | ▶ | sub value { | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 56 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 56 | ▶ | if(defined($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 28 | $self->{value} = $value; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 56 | return $self->{value}; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 223 | 4 | my $gb = CGI::Untaint::CountyStateProvince::GB->_new(); | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 4 | push @CGI::Untaint::CountyStateProvince::countries, $gb; | |||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | Nigel Horne, C<< <njh at bandsman.co.uk> >> | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =head1 BUGS | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | Please report any bugs or feature requests to C<bug-cgi-untaint-csp-gb at rt.cpan.org> | ||||||||||||||||||||||||||||
| 235 | or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Untaint-CountyStateProvince>. | ||||||||||||||||||||||||||||
| 236 | I will be notified, | ||||||||||||||||||||||||||||
| 237 | and then you'll | ||||||||||||||||||||||||||||
| 238 | automatically be notified of the progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | L<CGI::Untaint::CountyStateProvince>, L<CGI::Untaint>, L<Locale::SubCountry> | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | perldoc CGI::Untaint::CountyStateProvince::GB | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | You can also look for information at: | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =over 4 | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Untaint-CountyStateProvince-GB> | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | L<http://search.cpan.org/dist/CGI-Untaint-CountyStateProvince-GB> | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | =back | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | Copyright 2012-2025 Nigel Horne. | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | This program is released under the following licence: GPL2 | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 4 | 1; # End of CGI::Untaint::CountyStateProvince::GB | |||||||||||||||||||||||||||