File Coverage

blib/lib/IP/Geolocation/MMDB.pm
Criterion Covered Total %
statement 34 34 100.0
branch 5 8 62.5
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 51 54 94.4


line stmt bran cond sub pod time code
1             package IP::Geolocation::MMDB;
2              
3             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
4              
5 1     1   150100 use 5.016;
  1         7  
6 1     1   4 use warnings;
  1         2  
  1         34  
7 1     1   6 use utf8;
  1         1  
  1         12  
8              
9             our $VERSION = 1.009;
10              
11 1     1   413 use IP::Geolocation::MMDB::Metadata;
  1         2  
  1         28  
12 1     1   982 use Math::BigInt 1.999806;
  1         21866  
  1         5  
13              
14             require XSLoader;
15             XSLoader::load(__PACKAGE__, $VERSION);
16              
17             sub new {
18 3     3 1 916 my ($class, %attrs) = @_;
19              
20 3 100       17 my $file = $attrs{file} or die q{The "file" parameter is mandatory};
21 2         4 my $flags = 0;
22              
23 2         135 my $self = $class->_new($file, $flags);
24 1         5 bless $self, $class;
25              
26 1         4 return $self;
27             }
28              
29             sub getcc {
30 2     2 1 1811 my ($self, $ip_address) = @_;
31              
32 2         4 my $country_code;
33              
34 2         71 my $data = $self->record_for_address($ip_address);
35 2 50       1076 if (ref $data eq 'HASH') {
36 2 50       5 if (exists $data->{country}) {
37 2         4 my $country = $data->{country};
38 2 50       4 if (exists $country->{iso_code}) {
39 2         4 $country_code = $country->{iso_code};
40             }
41             }
42             }
43              
44 2         21 return $country_code;
45             }
46              
47             sub metadata {
48 1     1 1 6435 my ($self) = @_;
49              
50 1         3 return IP::Geolocation::MMDB::Metadata->new(%{$self->_metadata});
  1         23  
51             }
52              
53             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
54              
55             sub _to_bigint {
56 14     14   8619 my ($self, $bytes) = @_;
57              
58 14         42 return Math::BigInt->from_bytes($bytes);
59             }
60              
61             1;
62             __END__