File Coverage

blib/lib/Geo/Location/IP/Model/City.pm
Criterion Covered Total %
statement 87 87 100.0
branch 2 2 100.0
condition 13 20 65.0
subroutine 25 25 100.0
pod 11 11 100.0
total 138 145 95.1


line stmt bran cond sub pod time code
1             package Geo::Location::IP::Model::City;
2              
3             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
4              
5 12     12   945 use 5.026;
  12         41  
6 12     12   54 use warnings;
  12         22  
  12         606  
7 12     12   55 use utf8;
  12         20  
  12         65  
8              
9 12     12   278 use Object::Pad;
  12         18  
  12         61  
10              
11             class Geo::Location::IP::Model::City;
12              
13             our $VERSION = 0.005;
14              
15 12     12   10197 use Geo::Location::IP::Record::City;
  12         32  
  12         489  
16 12     12   5309 use Geo::Location::IP::Record::Continent;
  12         34  
  12         519  
17 12     12   5753 use Geo::Location::IP::Record::Country;
  12         34  
  12         511  
18 12     12   5787 use Geo::Location::IP::Record::Location;
  12         31  
  12         523  
19 12     12   5427 use Geo::Location::IP::Record::MaxMind;
  12         568  
  12         736  
20 12     12   5664 use Geo::Location::IP::Record::Postal;
  12         34  
  12         472  
21 12     12   5750 use Geo::Location::IP::Record::RepresentedCountry;
  12         30  
  12         505  
22 12     12   5692 use Geo::Location::IP::Record::Subdivision;
  12         34  
  12         570  
23 12     12   6030 use Geo::Location::IP::Record::Traits;
  12         34  
  12         19233  
24              
25 4     4 1 4220 field $city :param :reader;
  4         16  
26 2     2 1 11 field $continent :param :reader;
  2         7  
27 2     2 1 11 field $country :param :reader;
  2         9  
28 2     2 1 12 field $location :param :reader;
  2         7  
29 1     1 1 5 field $maxmind :param :reader;
  1         4  
30 1     1 1 4 field $postal :param :reader;
  1         3  
31 2     2 1 10 field $registered_country :param :reader;
  2         9  
32 2     2 1 10 field $represented_country :param :reader;
  2         8  
33             field $subdivisions :param;
34 3     3 1 17 field $traits :param :reader;
  3         12  
35              
36 3     3 1 9 method most_specific_subdivision () {
  3         13  
  3         5  
37 3 100       6 if (@{$subdivisions} > 0) {
  3         14  
38 2         8 return $subdivisions->[-1];
39             }
40 1         11 return Geo::Location::IP::Record::Subdivision->new(
41             names => {},
42             locales => [],
43             );
44             }
45              
46 1     1 1 3 method subdivisions () {
  1         4  
  1         1  
47 1         3 return @{$subdivisions};
  1         4  
48             }
49              
50 7     7   331104 sub _from_hash ($class, $hash_ref, $ip_address, $locales) {
  7         18  
  7         18  
  7         14  
  7         15  
  7         14  
51             my $city
52             = Geo::Location::IP::Record::City->_from_hash($hash_ref->{city} // {},
53 7   50     166 $locales);
54              
55             my $continent = Geo::Location::IP::Record::Continent->_from_hash(
56 7   50     99 $hash_ref->{continent} // {}, $locales);
57              
58             my $country
59             = Geo::Location::IP::Record::Country->_from_hash($hash_ref->{country}
60 7   50     156 // {}, $locales);
61              
62             my $location = Geo::Location::IP::Record::Location->_from_hash(
63 7   50     91 $hash_ref->{location} // {});
64              
65             my $maxmind
66             = Geo::Location::IP::Record::MaxMind->_from_hash($hash_ref->{maxmind}
67 7   100     88 // {});
68              
69             my $postal
70             = Geo::Location::IP::Record::Postal->_from_hash($hash_ref->{postal}
71 7   100     103 // {});
72              
73             my $registered_country = Geo::Location::IP::Record::Country->_from_hash(
74 7   50     50 $hash_ref->{registered_country} // {}, $locales);
75              
76             my $represented_country
77             = Geo::Location::IP::Record::RepresentedCountry->_from_hash(
78 7   50     85 $hash_ref->{represented_country} // {}, $locales);
79              
80             my @subdivisions = map {
81 10         104 Geo::Location::IP::Record::Subdivision->_from_hash($_, $locales)
82 7   100     19 } @{$hash_ref->{subdivisions} // []};
  7         44  
83              
84             my $traits
85             = Geo::Location::IP::Record::Traits->_from_hash($hash_ref->{traits}
86 7   50     80 // {}, $ip_address);
87              
88 7         161 return $class->new(
89             city => $city,
90             continent => $continent,
91             country => $country,
92             location => $location,
93             maxmind => $maxmind,
94             postal => $postal,
95             registered_country => $registered_country,
96             represented_country => $represented_country,
97             subdivisions => \@subdivisions,
98             traits => $traits,
99             );
100             }
101              
102             1;
103             __END__