Geo-Address-Formatter
view release on metacpan or search on metacpan
lib/Geo/Address/Formatter.pm view on Meta::CPAN
package Geo::Address::Formatter;
$Geo::Address::Formatter::VERSION = '1.9992';
# ABSTRACT: take structured address data and format it according to the various global/country rules
use strict;
use warnings;
use feature qw(say);
use Clone qw(clone);
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
use File::Basename qw(dirname);
use Ref::Util qw(is_hashref);
use Scalar::Util qw(looks_like_number);
use Text::Hogan::Compiler;
use Try::Catch;
use YAML::XS qw(LoadFile);
use utf8;
my $THC = Text::Hogan::Compiler->new;
# optional params
my $show_warnings = 1;
my $debug = 0;
my $only_address = 0;
my $instance;
sub instance {
my ($class, %params) = @_;
unless ($instance) {
$instance = $class->new(%params);
}
say STDERR "************* in Geo::Address::Formatter::instance ***" if ($debug);
# clear these fields that change on each run
$instance->{final_components} = undef;
$instance->{set_district_alias} = {};
return $instance;
}
sub new {
my ($class, %params) = @_;
my $self = {};
my $conf_path = $params{conf_path} || die "no conf_path set";
# optional params
if ( defined($params{no_warnings}) && ($params{no_warnings})){
$show_warnings = 0;
}
$only_address = (defined($params{only_address}) && $params{only_address}) // 0;
$debug = (defined($params{debug}) && $params{debug}) // 0;
$self->{final_components} = undef;
$self->{set_district_alias} = {};
bless($self, $class);
say STDERR "************* in Geo::Address::Formatter::new ***" if ($debug);
# is slow because lots of conf, and pre-compiling
if ($self->_read_configuration($conf_path)){
return $self;
}
die 'unable to read configuration';
}
( run in 1.748 second using v1.01-cache-2.11-cpan-39bf76dae61 )