blib/lib/CGI/Untaint/CountyStateProvince/GB.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 96.6% 57 / 59 CC 7 SCAR 11.9
CC
7
Cov
96%
is_valid
6.0
value
2.0
BEGIN
1.0
CRAP 3.3
↑ Summary
1 package CGI::Untaint::CountyStateProvince::GB;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Locale::SubCountry;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince);
9 3 ▶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.12
18  
19 =cut
20  
21 3 our $VERSION = '0.12';
22  
23 3 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 3 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 ▶ my $self = shift;
Subroutine is_valid: called CC=6 SCAR=18.0
Pod documented
178  
179 11 my $value = lc($self->value);
180  
181 11 ▶ if($value =~ /([a-z][a-z\s]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /([a-z][a-z\s]+)/) { } 10 1 11
182 10 $value = $1;
183 } else {
184 1 return 0;
185 }
186  
187 10 ▶ if(exists($abbreviations{$value})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $CGI::Untaint::CountyStateProvince::GB::abbreviations{$value}) 4 6 10
188 4 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 ▶ unless($self->{_validator}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_validator"}) 1 5 6
194 1 $self->{_validator} = Locale::SubCountry->new('GB');
195 1 ▶ unless($self->{_validator}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_validator"}) 0 1 1
196 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 ▶ return exists($counties{$value}) ? $value : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $CGI::Untaint::CountyStateProvince::GB::counties{$value} ? : 3 3 6
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 ▶ my ($self, $value) = @_;
Subroutine value: called CC=2 SCAR=6.9
Pod documented
217  
218 22 ▶ if(defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 11 11 22
219 11 $self->{value} = $value;
220 }
221  
222 22 return $self->{value};
223 }
224  
225 BEGIN {
226 3 ▶ my $gb = CGI::Untaint::CountyStateProvince::GB->_new();
Subroutine BEGIN: called CC=1 SCAR=0.0
227  
228 3 push @CGI::Untaint::CountyStateProvince::countries, $gb;
229 };
230  
231 =head1 AUTHOR
232  
233 Nigel Horne, C<< <njh at bandsman.co.uk> >>
234  
235 =head1 BUGS
236  
237 Please report any bugs or feature requests to C<bug-cgi-untaint-csp-gb at rt.cpan.org>, or through
238 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Untaint-CountyStateProvince>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Untaint-CountyStateProvince-GB>
259  
260 =item * CPAN Ratings
261  
262 L<http://cpanratings.perl.org/d/CGI-Untaint-CountyStateProvince-GB>
263  
264 =item * Search CPAN
265  
266 L<http://search.cpan.org/dist/CGI-Untaint-CountyStateProvince-GB>
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 3 1; # End of CGI::Untaint::CountyStateProvince::GB
↑ Summary