Reader/Role/Reader.pm

filter: Statementstmt 92.6% 38 / 41 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 90.3% 56 / 62 CC 4 SCAR 6.3
CC
4
Cov
92%
record_for_address
4.0
__ANON__
1.1
BEGIN
1.0
CRAP 1.9
« Reader/Role/NodeReader.pm ↑ Summary Reader/Role/HasMetadata.pm »
1 package MaxMind::DB::Reader::Role::Reader;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 21 our $VERSION = '1.000014';
9  
10 21 ▶use Data::Validate::IP 0.25 qw( is_ip );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use MaxMind::DB::Types qw( Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 21 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 21 requires qw(
16 _build_metadata
17 _data_for_address
18 );
19  
20 21 ▶use constant DEBUG => $ENV{MAXMIND_DB_READER_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 has file => (
23 is => 'ro',
24 isa => Str,
25 22 ▶ coerce => sub {"$_[0]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
26 21 required => 1,
27 );
28  
29 209 ▶sub record_for_address {
Subroutine record_for_address: called CC=4 SCAR=13.9
Pod undocumented
30 209 my $self = shift;
31 209 my $addr = shift;
32  
33 209 ▶ die 'You must provide an IP address to look up'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addr and length $addr 1 208 209
Condition66%2/3
defined $addr and length $addr
!ll&&!rl&&r
10208
MC/DC50%1/2
defined $addr and length $addr
defined $addr length $addr
Truth table66%2/3
A and B
A= defined $addrB= length $addr
ABresult
0X0
100
111
34 unless defined $addr && length $addr;
35  
36 # We validate the IP address here as libmaxminddb allows more liberal
37 # numbers and dots notation for IPv4 (e.g., `1.1.1` or `01.1.1.1`) rather
38 # than requiring the standard dotted quad due to using getaddrinfo.
39 208 ▶ die
Branch: 1 branch
BranchTrueFalseTotal
unless is_ip($addr) 5 203 208
40 "The IP address you provided ($addr) is not a valid IPv4 or IPv6 address"
41 unless is_ip($addr);
42  
43 203 return $self->_data_for_address($addr);
44 }
45  
46 21 ▶around _build_metadata => sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
47 21 my $orig = shift;
48 21 my $self = shift;
49  
50 21 return $self->$orig(@_) unless DEBUG;
51  
52 0 my $metadata = $self->$orig(@_);
53  
54 0 $metadata->debug_dump;
55  
56 0 return $metadata;
57 21 };
58  
59 21 1;
« Reader/Role/NodeReader.pm ↑ Summary Reader/Role/HasMetadata.pm »