| 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
Condition66%2/3
defined $addr and length $addr
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||