line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::country; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
36033
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
32
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1134
|
use Locale::Country(); |
|
1
|
|
|
|
|
42867
|
|
|
1
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
9
|
use base 'CGI::Untaint::printable'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13885
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
CGI::Untaint::country - validate a country code or name |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 0.2; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use CGI::Untaint; |
21
|
|
|
|
|
|
|
my $handler = CGI::Untaint->new($q->Vars); |
22
|
|
|
|
|
|
|
# submit: |
23
|
|
|
|
|
|
|
$country_code2 = $handler->extract(-as_country => 'country'); # 2 letter code e.g. 'uk' |
24
|
|
|
|
|
|
|
$country_code2 = $handler->extract(-as_countrycode => 'country'); # same as above |
25
|
|
|
|
|
|
|
$country_name = $handler->extract(-as_countryname => 'country'); # name e.g. 'United Kingdom' |
26
|
|
|
|
|
|
|
$country_code3 = $handler->extract(-as_countrycode3 => 'country'); # 3 letter code e.g. 'gbr' |
27
|
|
|
|
|
|
|
$country_code2 = $handler->extract(-as_to_countrycode => 'country'); # name |
28
|
|
|
|
|
|
|
$country_code3 = $handler->extract(-as_to_countrycode3 => 'country'); # name |
29
|
|
|
|
|
|
|
$country_codenum = $handler->extract(-as_countrynumber => 'country'); # numeric code e.g. '064' |
30
|
|
|
|
|
|
|
$country_codenum = $handler->extract(-as_to_countrynumber => 'country'); # name |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Verifies that the submitted value is a valid ISO 3166-1 country code, or a known name. |
36
|
|
|
|
|
|
|
See L. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 4 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item is_valid |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=back |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub is_valid { |
49
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $codeset = $self->_codeset; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# code in, code out |
54
|
0
|
|
|
|
|
|
return Locale::Country::code2country( $self->value, $codeset ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
|
|
sub _codeset { Locale::Constants::LOCALE_CODE_ALPHA_2 } |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
David Baird, C<< >> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 BUGS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
66
|
|
|
|
|
|
|
C, or through the web interface at |
67
|
|
|
|
|
|
|
L. I will be notified, and then you'll automatically |
68
|
|
|
|
|
|
|
be notified of progress on your bug as I make changes. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Copyright 2005 David Baird, All Rights Reserved. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
77
|
|
|
|
|
|
|
under the same terms as Perl itself. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |