1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
package GeoIP2::Role::Model::HasSubdivisions;
use strict;
use warnings;
our $VERSION = '2.006002';
use Moo::Role;
use GeoIP2::Record::Subdivision;
use GeoIP2::Types qw( ArrayRef object_isa_type );
use Sub::Quote qw( quote_sub );
use namespace::clean;
with 'GeoIP2::Role::HasLocales';
has _raw_subdivisions => (
is => 'ro',
isa => ArrayRef,
init_arg => 'subdivisions',
lazy => 1,
default => quote_sub(q{ [] }),
);
has _subdivisions => (
is => 'ro',
isa => ArrayRef,
init_arg => undef,
lazy => 1,
builder => '_build_subdivisions',
);
has most_specific_subdivision => (
is => 'ro',
isa => quote_sub(
q{ GeoIP2::Types::object_isa_type( $_[0], 'GeoIP2::Record::Subdivision' ) },
),
init_arg => undef,
lazy => 1,
builder => '_build_most_specific_subdivision',
);
sub subdivisions {
return @{ $_[0]->_subdivisions() };
}
sub _build_subdivisions {
my $self = shift;
return [
map {
GeoIP2::Record::Subdivision->new(
%{$_},
locales => $self->locales(),
);
} @{ $self->_raw_subdivisions() }
];
}
sub _build_most_specific_subdivision {
my $self = shift;
my @subdivisions = $self->subdivisions();
return $subdivisions[-1] if @subdivisions;
return GeoIP2::Record::Subdivision->new(
locales => $self->locales(),
);
}
1;
|