File Coverage

blib/lib/Geo/Location/IP/Model/Country.pm
Criterion Covered Total %
statement 51 51 100.0
branch n/a
condition 7 12 58.3
subroutine 16 16 100.0
pod 6 6 100.0
total 80 85 94.1


line stmt bran cond sub pod time code
1             package Geo::Location::IP::Model::Country;
2              
3             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
4              
5 11     11   719 use 5.026;
  11         37  
6 11     11   53 use warnings;
  11         18  
  11         516  
7 11     11   51 use utf8;
  11         16  
  11         53  
8              
9 11     11   270 use Object::Pad;
  11         16  
  11         57  
10              
11             class Geo::Location::IP::Model::Country;
12              
13             our $VERSION = 0.005;
14              
15 11     11   4186 use Geo::Location::IP::Record::Continent;
  11         29  
  11         318  
16 11     11   468 use Geo::Location::IP::Record::Country;
  11         21  
  11         295  
17 11     11   427 use Geo::Location::IP::Record::MaxMind;
  11         15  
  11         237  
18 11     11   402 use Geo::Location::IP::Record::RepresentedCountry;
  11         16  
  11         319  
19 11     11   483 use Geo::Location::IP::Record::Traits;
  11         20  
  11         7663  
20              
21 2     2 1 594 field $continent :param :reader;
  2         7  
22 2     2 1 8 field $country :param :reader;
  2         7  
23 1     1 1 3 field $maxmind :param :reader;
  1         3  
24 2     2 1 9 field $registered_country :param :reader;
  2         6  
25 2     2 1 7 field $represented_country :param :reader;
  2         6  
26 2     2 1 9 field $traits :param :reader;
  2         7  
27              
28 2     2   28 sub _from_hash ($class, $hash_ref, $ip_address, $locales) {
  2         6  
  2         4  
  2         4  
  2         3  
  2         2  
29             my $continent = Geo::Location::IP::Record::Continent->_from_hash(
30 2   50     25 $hash_ref->{continent} // {}, $locales);
31              
32             my $country
33             = Geo::Location::IP::Record::Country->_from_hash($hash_ref->{country}
34 2   50     25 // {}, $locales);
35              
36             my $maxmind
37             = Geo::Location::IP::Record::MaxMind->_from_hash($hash_ref->{maxmind}
38 2   100     30 // {});
39              
40             my $registered_country = Geo::Location::IP::Record::Country->_from_hash(
41 2   50     12 $hash_ref->{registered_country} // {}, $locales);
42              
43             my $represented_country
44             = Geo::Location::IP::Record::RepresentedCountry->_from_hash(
45 2   50     56 $hash_ref->{represented_country} // {}, $locales);
46              
47             my $traits
48             = Geo::Location::IP::Record::Traits->_from_hash($hash_ref->{traits}
49 2   50     25 // {}, $ip_address);
50              
51 2         27 return $class->new(
52             continent => $continent,
53             country => $country,
54             maxmind => $maxmind,
55             registered_country => $registered_country,
56             represented_country => $represented_country,
57             traits => $traits,
58             );
59             }
60              
61             1;
62             __END__