blib/lib/CGI/Untaint/CountyStateProvince.pm

filter: Statementstmt 68.9% 20 / 29 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 66.6% 28 / 42 CC 5 SCAR 20.8
CC
5
Cov
60%
is_valid
15.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.0
↑ Summary
1 package CGI::Untaint::CountyStateProvince;
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 Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶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.06
17  
18 =cut
19  
20 3 our $VERSION = '0.06';
21  
22 3 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 sub _untaint_re {
66 # Only allow letters and spaces
67 7 ▶ return qr/^([a-zA-z\s]+)$/;
Subroutine _untaint_re: called CC=1 SCAR=0.0
68 }
69  
70 sub is_valid {
71 3 ▶ my $self = shift;
Subroutine is_valid: called CC=5 SCAR=27.1
Pod documented
72  
73 3 ▶ unless(scalar(@countries) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @CGI::Untaint::CountyStateProvince::countries > 0) 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 0 my $new_value = $country->is_valid();
83 0 ▶ if($new_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_value) { } 0 0 0
84 0 ▶ if($new_value ne $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_value ne $value) 0 0 0
85 0 $self->value($new_value);
86 }
87 } else {
88 0 return 0;
89 }
90 }
91  
92 0 return 1;
93 }
94  
95 =head1 AUTHOR
96  
97 Nigel Horne, C<< <njh at bandsman.co.uk> >>
98  
99 =head1 BUGS
100  
101 Please report any bugs or feature requests to C<bug-cgi-untaint-countystateprovince at rt.cpan.org>, or through
102 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Untaint-CountyStateProvince>. I will be notified, and then you'll
103 automatically be notified of progress on your bug as I make changes.
104  
105  
106 =head1 SEE ALSO
107  
108 CGI::Untaint
109  
110  
111 =head1 SUPPORT
112  
113 You can find documentation for this module with the perldoc command.
114  
115 perldoc CGI::Untaint::CountyStateProvince
116  
117  
118 You can also look for information at:
119  
120 =over 4
121  
122 =item * RT: CPAN's request tracker
123  
124 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Untaint-CountyStateProvince>
125  
126 =item * CPAN Ratings
127  
128 L<http://cpanratings.perl.org/d/CGI-Untaint-CountyStateProvince>
129  
130 =item * Search CPAN
131  
132 L<http://search.cpan.org/dist/CGI-Untaint-CountyStateProvince>
133  
134 =back
135  
136  
137 =head1 ACKNOWLEDGEMENTS
138  
139  
140 =head1 LICENSE AND COPYRIGHT
141  
142 Copyright 2012-2019 Nigel Horne.
143  
144 This program is released under the following licence: GPL2
145  
146 =cut
147  
148 3 1; # End of CGI::Untaint::CountyStateProvince
↑ Summary