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