NAME

Geo::Address::Parser::Country - Resolve a place string component to a canonical country name

VERSION

Version 0.02

SYNOPSIS

use Geo::Address::Parser::Country;
use Locale::US;
use Locale::CA;
use Locale::AU;

my $resolver = Geo::Address::Parser::Country->new({
    us    => Locale::US->new(),
    ca_en => Locale::CA->new(lang => 'en'),
    ca_fr => Locale::CA->new(lang => 'fr'),
    au    => Locale::AU->new(),
});

my $result = $resolver->resolve(
    component => 'England',
    place     => 'Ramsgate, Kent, England',
);

# $result->{country}  eq 'United Kingdom'
# $result->{place}    eq 'Ramsgate, Kent, England'
# $result->{warnings} is []
# $result->{unknown}  is 0

DESCRIPTION

Resolves the last comma-separated component of a place string into a canonical country name. Handles common variants, abbreviations, and historical names found in genealogy data and other poorly-normalised address sources.

Designed specifically to tolerate poor-quality data from software imports where place strings may be inconsistent, abbreviated, or use historical country names no longer in common use.

Resolution proceeds through the following steps in order:

TODO

METHODS

new

Purpose

Constructs a new resolver object. The locale objects are used for state and province lookups and are retained for the lifetime of the object.

API Specification

Input

{
    us    => { type => 'object', can => 'new' },  # Locale::US instance
    ca_en => { type => 'object', can => 'new' },  # Locale::CA English instance
    ca_fr => { type => 'object', can => 'new' },  # Locale::CA French instance
    au    => { type => 'object', can => 'new' },  # Locale::AU instance
    geonames => {                                  # Optional Geo::GeoNames instance
        type     => 'object',
        can      => 'search',
        optional => 1,
    },
}

Output

{ type => 'object', isa => 'Geo::Address::Parser::Country' }

Arguments

Returns

A blessed Geo::Address::Parser::Country object.

Side Effects

None.

Notes

The locale objects are stored by reference and shared for all calls to resolve(). Constructing them once and reusing the resolver object is more efficient than constructing a new resolver for each lookup.

Example

my $resolver = Geo::Address::Parser::Country->new({
    us    => Locale::US->new(),
    ca_en => Locale::CA->new(lang => 'en'),
    ca_fr => Locale::CA->new(lang => 'fr'),
    au    => Locale::AU->new(),
});

resolve

Purpose

Resolves the last comma-separated component of a place string to a canonical country name, and returns the (possibly modified) place string alongside any warnings generated during resolution.

API Specification

Input

{
    component => { type => 'string', min => 1 },
    place     => { type => 'string', min => 1 },
}

Output

{
    type   => 'hashref',
    schema => {
        country  => { type => 'string',   optional => 1 },
        place    => { type => 'string',   min => 1 },
        warnings => { type => 'arrayref' },
        unknown  => { type => 'boolean' },
    },
}

Arguments

Returns

A hashref containing:

Side Effects

None. All warnings are returned to the caller rather than emitted directly.

Notes

Resolution order is: direct lookup, US state, Canadian province, Australian state, Locale::Object::Country, GeoNames (if available). The first successful match wins.

When a US state, Canadian province, or Australian state is recognised, the appropriate country string (", USA", ", Canada", ", Australia") is appended to place if not already present.

Example

my $result = $resolver->resolve(
    component => 'TX',
    place     => 'Houston, TX',
);

# $result->{country}     eq 'United States'
# $result->{place}       eq 'Houston, TX, USA'
# $result->{warnings}[0] eq 'TX: assuming country is United States'
# $result->{unknown}     is 0

AUTHOR

Nigel Horne <njh@nigelhorne.com>

REPOSITORY

https://github.com/nigelhorne/Geo-Address-Parser-Country

SUPPORT

This module is provided as-is without any warranty.

Please report any bugs or feature requests to bug-geo-address-parser at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geo-Address-Parser-Country. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

BUGS

Please report additional bugs via the GitHub issue tracker: https://github.com/nigelhorne/Geo-Address-Parser-Country/issues

SEE ALSO

LICENCE AND COPYRIGHT

Copyright 2026 Nigel Horne.

Usage is subject to licence terms.

The licence terms of this software are as follows: