CGI::Untaint::country - validate a country code or name


CGI-Untaint-country documentation Contained in the CGI-Untaint-country distribution.

Index


Code Index:

NAME

Top

CGI::Untaint::country - validate a country code or name

SYNOPSIS

Top

    use CGI::Untaint;
    my $handler = CGI::Untaint->new($q->Vars);
                                                                                # submit:
    $country_code2   = $handler->extract(-as_country          => 'country');    # 2 letter code e.g. 'uk'
    $country_code2   = $handler->extract(-as_countrycode      => 'country');    # same as above 
    $country_name    = $handler->extract(-as_countryname      => 'country');    # name e.g. 'United Kingdom'
    $country_code3   = $handler->extract(-as_countrycode3     => 'country');    # 3 letter code e.g. 'gbr'
    $country_code2   = $handler->extract(-as_to_countrycode   => 'country');    # name
    $country_code3   = $handler->extract(-as_to_countrycode3  => 'country');    # name
    $country_codenum = $handler->extract(-as_countrynumber    => 'country');    # numeric code e.g. '064'
    $country_codenum = $handler->extract(-as_to_countrynumber => 'country');    # name




DESCRIPTION

Top

Verifies that the submitted value is a valid ISO 3166-1 country code, or a known name. See Locale::Country.

METHODS

Top

is_valid

AUTHOR

Top

David Baird, <cpan@riverside-cms.co.uk>

BUGS

Top

Please report any bugs or feature requests to bug-cgi-untaint-country@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


CGI-Untaint-country documentation Contained in the CGI-Untaint-country distribution.
package CGI::Untaint::country;

use warnings;
use strict;

use Locale::Country();

use base 'CGI::Untaint::printable';

our $VERSION = 0.2;

sub is_valid {
    my ( $self ) = @_;
    
    my $codeset = $self->_codeset;
    
    # code in, code out
    return Locale::Country::code2country( $self->value, $codeset );
}

sub _codeset { Locale::Constants::LOCALE_CODE_ALPHA_2 }

1;