blib/lib/CGI/Untaint/CountyStateProvince.pm

filter: Statementstmt 74.0% 20 / 27 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 70.0% 28 / 40 CC 5 SCAR 20.0
CC
5
Cov
64%
is_valid
13.8
BEGIN
1.0
BEGIN
1.0
CRAP 7.4
↑ Summary
1 package CGI::Untaint::CountyStateProvince;
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 Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use base 'CGI::Untaint::object';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 CGI::Untaint::CountyStateProvince - Validate a state, county or province in a
12 CGI script.
13  
14 =head1 VERSION
15  
16 Version 0.07
17  
18 =cut
19  
20 4 our $VERSION = '0.07';
21  
22 4 our @countries;
23  
24 =head1 SYNOPSIS
25  
26 CGI::Untaint::CountyStateProvince is a subclass of CGI::Untaint used to
27 validate if the given user data is a valid county/state/province.
28  
29 This class is not to be instantiated, instead a subclass must be
30 instantiated. For example L<CGI::Untaint::CountyStateProvince::GB> would
31 validate against a British county, L<CGI::Untaint::CountyStateProvince::US>
32 would validate against a US state, and so on.
33  
34 use CGI::Info;
35 use CGI::Untaint;
36 use CGI::Untaint::CountyStateProvince;
37 # ...
38 my $info = CGI::Info->new();
39 my $params = $info->params();
40 # ...
41 # Country table(s) must be loaded after CGI::Untaint::CountyStateProvince
42 if($params->{'country'} == 44) {
43 require CGI::Untaint::CountyStateProvince::GB;
44  
45 CGI::Untaint::CountyStateProvince::GB->import();
46 } elsif($params->{'country'} == 1) {
47 require CGI::Untaint::CountyStateProvince::US;
48  
49 CGI::Untaint::CountyStateProvince::US->import();
50 } else {
51 die 'Unsupported country ', $params->{'country'};
52 }
53 my $u = CGI::Untaint->new($params);
54 my $csp = $u->extract(-as_CountyStateProvince => 'state');
55 # $csp will be lower case
56  
57 =head1 SUBROUTINES/METHODS
58  
59 =head2 is_valid
60  
61 Validates the data.
62  
63 =cut
64  
65 8 ▶sub _untaint_re {
Subroutine _untaint_re: called CC=1 SCAR=0.0
66 # Only allow letters and spaces
67 8 return qr/^([a-zA-Z\s]+)$/;
68 }
69  
70 3 ▶sub is_valid {
Subroutine is_valid: called CC=5 SCAR=26.2
Pod documented
71 3 my $self = shift;
72  
73 3 ▶ unless(@countries) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@CGI::Untaint::CountyStateProvince::countries) 3 0 3
74 3 carp 'You must specify at least one country';
75 3 return 0;
76 }
77  
78 0 my $value = $self->value();
79  
80 0 foreach my $country(@countries) {
81 0 $country->value($value);
82  
83 0 ▶ if(my $new_value = $country->is_valid()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $new_value = $country->is_valid) { } 0 0 0
84 0 ▶ $self->value($new_value) if $new_value ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if $new_value ne $value 0 0 0
85 } else {
86 0 return 0;
87 }
88 }
89  
90 0 return 1;
91 }
92  
93  
94 =head1 AUTHOR
95  
96 Nigel Horne, C<< <njh at bandsman.co.uk> >>
97  
98 =head1 BUGS
99  
100 Please report any bugs or feature requests to C<bug-cgi-untaint-countystateprovince at rt.cpan.org>, or through
101 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Untaint-CountyStateProvince>. I will be notified, and then you'll
102 automatically be notified of progress on your bug as I make changes.
103  
104 =head1 SEE ALSO
105  
106 CGI::Untaint
107  
108 =head1 SUPPORT
109  
110 You can find documentation for this module with the perldoc command.
111  
112 perldoc CGI::Untaint::CountyStateProvince
113  
114 You can also look for information at:
115  
116 =over 4
117  
118 =item * RT: CPAN's request tracker
119  
120 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Untaint-CountyStateProvince>
121  
122 =item * Search CPAN
123  
124 L<http://search.cpan.org/dist/CGI-Untaint-CountyStateProvince>
125  
126 =back
127  
128 =head1 ACKNOWLEDGEMENTS
129  
130  
131 =head1 LICENSE AND COPYRIGHT
132  
133 Copyright 2012-2025 Nigel Horne.
134  
135 This program is released under the following licence: GPL2
136  
137 =cut
138  
139 4 1; # End of CGI::Untaint::CountyStateProvince
↑ Summary