Locale::Geocode::Division - Locale::Geocode::Division documentation


Locale-Geocode documentation Contained in the Locale-Geocode distribution.

Index


Code Index:

NAME

Top

Locale::Geocode::Division

DESCRIPTION

Top

Locale::Geocode::Division provides methods for accessing information regarding administrative divisions within territories as defined by ISO-3166-2.

SYNOPSIS

Top

 my $lct    = new Locale::Geocode::Division 'US';

 # lookup a subdivision of US
 my $lcd    = $lct->lookup('TN');

 # retrieve ISO-3166-2 information for US-TN
 my $name   = $lcd->name;   # Tennessee
 my $code   = $lcd->code;   # TN

 # returns an array of Locale::Geocode::Division
 # objects representing all divisions of US
 my @divs   = $lct->divisions;

METHODS

Top

new
name
code
fips
region
parent
has_notes
num_notes
notes
note

AUTHOR

Top

 Mike Eldridge <diz@cpan.org>

CREDITS

Top

 Kim Ryan

SEE ALSO

Top

 L<Locale::Geocode>
 L<Locale::Geocode::Territory>


Locale-Geocode documentation Contained in the Locale-Geocode distribution.
package Locale::Geocode::Division;

use warnings;
use strict;

use overload '""' => sub { return shift->code };

our @meta = qw(name code fips region has_notes num_notes);

sub new
{
	my $proto	= shift;
	my $key		= lc(shift);
	my $lct		= shift;

	my $class	= ref($proto) || $proto;
	my $self	= {};

	$self->{territory} = $lct;

	$self->{data} =	$lct->{data}->{divs_code}->{$key} ||
					$lct->{data}->{divs_fips}->{$key} ||
					$lct->{data}->{divs_name}->{$key};

	return undef if not defined $self->{data};
	return undef if not $lct->lg->chkext($self->{data});

	return bless $self, $class;
}

sub name { return shift->{data}->{name} }

sub code { return shift->{data}->{code} }

sub fips { return shift->{data}->{fips} }

sub region { return shift->{data}->{region} }

sub parent { return shift->{territory} }

sub has_notes { return scalar @{ shift->{notes} } > 0 ? 1 : 0 }

sub num_notes { return scalar @{ shift->{notes} } }

sub notes { return @{ shift->{notes} } }

sub note { return shift->{notes}->[shift] }

1;