country.pm

filter: Statementstmt 75.0% 12 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod n/a totaltotal 72.7% 16 / 22 CC 1 SCAR 2.9
CC
1
Cov
75%
is_valid
2.0
_codeset
2.0
BEGIN
1.0
CRAP 1.3
« to_countrynumber.pm ↑ Summary
1 package CGI::Untaint::country;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Locale::Country();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base 'CGI::Untaint::printable';
Subroutine BEGIN: called CC=1 SCAR=0.0
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<Locale::Country|Locale::Country>.
37  
38 =head1 METHODS
39  
40 =over 4
41  
42 =item is_valid
43  
44 =back
45  
46 =cut
47  
48 0 ▶sub is_valid {
Subroutine is_valid: not called CC=1 SCAR=6.9
49 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 ▶sub _codeset { Locale::Constants::LOCALE_CODE_ALPHA_2 }
Subroutine _codeset: not called CC=1 SCAR=6.9
58  
59 =head1 AUTHOR
60  
61 David Baird, C<< <cpan@riverside-cms.co.uk> >>
62  
63 =head1 BUGS
64  
65 Please report any bugs or feature requests to
66 C<bug-cgi-untaint-country@rt.cpan.org>, or through the web interface at
67 L<http://rt.cpan.org>. 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;
« to_countrynumber.pm ↑ Summary