Locale::Object::Country - country information objects


Locale-Object documentation  | view source Contained in the Locale-Object distribution.

Index


NAME

Top

Locale::Object::Country - country information objects

DESCRIPTION

Top

Locale::Object::Country allows you to create objects containing information about countries such as their ISO codes, currencies and so on.

SYNOPSIS

Top

    use Locale::Object::Country;

    my $country = Locale::Object::Country->new( code_alpha2 => 'af' );

    my $name         = $country->name;         # 'Afghanistan'
    my $code_alpha3  = $country->code_alpha3;  # 'afg'
    my $dialing_code = $country->dialing_code; # '93'

    my $currency     = $country->currency;
    my $continent    = $country->continent;

    my @languages    = $country->languages;
    my @official     = $country->languages_official;

    my $timezone     = $country->timezone;
    my @allzones     = @{$country->all_timezones};

METHODS

Top

new()

    my $country = Locale::Object::Country->new( code => 'af' );

The new method creates an object. It takes a single-item hash as an argument - valid options to pass are ISO 3166 values - 'code_alpha2', 'code_alpha3', 'code_numeric' and 'name'. See Locale::Object::DB::Schemata for details on these.

The objects created are singletons; if you try and create a country object when one matching your specification already exists, new() will return the original one.

code_alpha2(), code_alpha3(), code_numeric(), name(), dialing_code()

    my $name = $country->name;

These methods retrieve the values of the attributes whose name they share in the object.

currency(), continent()

These methods return Locale::Object::Currency and Locale::Object::Continent objects respectively. Both of those have their own attribute methods, so you can do things like this:

    my $currency      = $country->currency;
    my $currency_name = $currency->name;

See the documentation for those two modules for a listing of currency and continent attributes.

Note: More attributes will be added in a future release; see Locale::Object::DB::Schemata for a full listing of the contents of the database.

languages(), languages_official()

    my @languages = $country->languages;

languages() returns an array of Locale::Object::Language objects in array context, or a reference in scalar context. The objects have their own attribute methods, so you can do things like this:

    foreach my $lang (@languages)
    {
      print $lang->name, "\n";
    }

languages_official() does much the same thing, but only gives languages that are official in that country. Note: you can also use the official() method of a Locale::Object::Language object on a country object; this will return a boolean value describing whether the language is official in that country.

timezone()

    my $timezone = $country->timezone;

This method will return you a DateTime::TimeZone object corresponding with the time zone in the capital of the country your object represents. See the documentation for that module to see what methods it provides; as a simple example:

    my $timezone_name = $timezone->name;

all_timezones()

    my @allzones     = @{$country->all_timezones};

This method will return an array or array reference, depending on context, of DateTime::TimeZone objects for all time zones that occur in the country your object represents. In most cases this will be only one, and in some cases it will be quite a few (for example, the US, Canada, and Russian Federation).

AUTHOR

Top

Earle Martin <hex@cpan.org>

http://downlode.org/Code/Perl/

CREDITS

Top

See the credits for Locale::Object.

LEGAL

Top


Locale-Object documentation  | view source Contained in the Locale-Object distribution.