| 1 | package CGI::Untaint::CountyStateProvince::US; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 7 | # use base qw(CGI::Untaint::object CGI::Untaint::CountyStateProvince); | ||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use base 'CGI::Untaint::object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | CGI::Untaint::CountyStateProvince::US - Add U.S. states to CGI::Untaint::CountyStateProvince tables | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Version 0.03 | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Adds a list of U.S. states to the list of counties/state/provinces | ||||||||||||||||||||||||||||
| 25 | which are known by the CGI::Untaint::CountyStateProvince validator allowing you | ||||||||||||||||||||||||||||
| 26 | to verify that a field in an HTML form contains a valid U.S. state. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | You must include CGI::Untaint::CountyStateProvince::US after including | ||||||||||||||||||||||||||||
| 29 | CGI::Untaint, otherwise it won't work. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | use CGI::Info; | ||||||||||||||||||||||||||||
| 32 | use CGI::Untaint; | ||||||||||||||||||||||||||||
| 33 | use CGI::Untaint::CountyStateProvince::US; | ||||||||||||||||||||||||||||
| 34 | my $info = CGI::Info->new(); | ||||||||||||||||||||||||||||
| 35 | my $u = CGI::Untaint->new($info->params()); | ||||||||||||||||||||||||||||
| 36 | # Succeeds if state = 'MD' or 'Maryland', fails if state = 'Queensland'; | ||||||||||||||||||||||||||||
| 37 | $u->extract(-as_CountyStateProvince => 'state'); | ||||||||||||||||||||||||||||
| 38 | # ... | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 SUBSOUTINES/METHODS | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head2 is_valid | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Validates the data, setting the data to be the two letter abbreviation for the | ||||||||||||||||||||||||||||
| 47 | given state. See CGI::Untaint::is_valid. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub is_valid { | ||||||||||||||||||||||||||||
| 52 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | my $value = uc($self->value); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 6 | ▶ | if($value =~ /([A-Z][A-Z\s]+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 5 | $value = $1; | |||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||
| 59 | 1 | return 0; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 5 | ▶ | unless($self->{_validator}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 1 | $self->{_validator} = Locale::SubCountry->new('US'); | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | unless($self->{_validator}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | return 0; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | my $state = $self->{_validator}->code($value); | |||||||||||||||||||||||||||
| 70 | 5 | ▶ | if($state && ($state ne 'unknown')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state and $state ne "unknown"
MC/DC50%1/2
$state and $state ne "unknown"
$state
$state ne "unknown"
Truth table66%2/3
A and B
A= $stateB= $state ne "unknown"
| |||||||||||||||||||||||||||||
| 71 | # Given full state name | ||||||||||||||||||||||||||||
| 72 | # Detaintify | ||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if($state =~ /(^[A-Z]{2}$)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 1 | return $1; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 4 | $state = $self->{_validator}->full_name($value); | |||||||||||||||||||||||||||
| 79 | 4 | ▶ | if($state && ($state ne 'unknown')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state and $state ne "unknown"
MC/DC50%1/2
$state and $state ne "unknown"
$state
$state ne "unknown"
Truth table66%2/3
A and B
A= $stateB= $state ne "unknown"
| |||||||||||||||||||||||||||||
| 80 | # Given two letter abbreviation | ||||||||||||||||||||||||||||
| 81 | 2 | return $value; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | return 0; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 value | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Sets the raw data which is to be validated. Called by the superclass, you | ||||||||||||||||||||||||||||
| 90 | are unlikely to want to call it. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub value { | ||||||||||||||||||||||||||||
| 95 | 12 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 12 | ▶ | if(defined($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 6 | $self->{value} = $value; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 12 | return $self->{value}; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | BEGIN { | ||||||||||||||||||||||||||||
| 105 | 3 | ▶ | my $us = CGI::Untaint::CountyStateProvince::US->_new(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3 | push @CGI::Untaint::CountyStateProvince::countries, $us; | |||||||||||||||||||||||||||
| 108 | }; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Nigel Horne, C<< <njh at bandsman.co.uk> >> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 BUGS | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Only two letter abbreviations are allowable, so 'Mass' won't work for | ||||||||||||||||||||||||||||
| 117 | Massachusetts. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Please report any bugs or feature requests to C<bug-cgi-untaint-csp-us at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 120 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Untaint-CountyStateProvince>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 121 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | CGI::Untaint::CountyStateProvince, CGI::Untaint | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | perldoc CGI::Untaint::CountyStateProvince::US | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | You can also look for information at: | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =over 4 | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Untaint-CountyStateProvince-US> | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | L<http://annocpan.org/dist/CGI-Untaint-CountyStateProvince-US> | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | L<http://cpanratings.perl.org/d/CGI-Untaint-CountyStateProvince-US> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | L<http://search.cpan.org/dist/CGI-Untaint-CountyStateProvince-US> | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =back | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Copyright 2012 Nigel Horne. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | This program is released under the following licence: GPL | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 3 | 1; # End of CGI::Untaint::CountyStateProvince::US | |||||||||||||||||||||||||||