| 1 | package Net::CIDR::MobileJP; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use 5.00800; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Net::CIDR::Lite; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use File::ShareDir (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.24'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $yaml_loader; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | $yaml_loader = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | if (eval "use YAML::Syck; 1;") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | \&YAML::Syck::LoadFile; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | require YAML; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | \&YAML::LoadFile; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | }->(); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | my ($class, $stuff) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | return bless {spanner => $class->_create_spanner($class->_load_config($stuff))}, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | sub _create_spanner { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_spanner: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | my ($class, $conf) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my $spanner = Net::CIDR::Lite::Span->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | while (my ($carrier, $ip_ranges) = each %$conf) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | $spanner->add(do { | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 12 | my $cidr = Net::CIDR::Lite->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 12 | for my $ip_range (@$ip_ranges) { | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 282 | $cidr->add($ip_range); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 12 | $cidr; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | }, $carrier); | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | return $spanner; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | sub _load_config { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_config: called CC=7 SCAR=31.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | my ($self, $stuff) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | if (defined $stuff && -f $stuff && -r _) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $stuff and -f $stuff and -r _
defined $stuff and -f $stuff
MC/DC0%0/3
defined $stuff and -f $stuff and -r _
defined $stuff
-f $stuff
-r _
Truth table25%1/4
A and B and C
A= defined $stuffB= -f $stuffC= -r _
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # load yaml from file | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | $data = $yaml_loader->($stuff); | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif ($stuff) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # raw data | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $data = $stuff; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # generated file | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | my $file = eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # use module_file first, this is needed by backward-compatibility | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | File::ShareDir::module_file( 'Net::CIDR::MobileJP', 'cidr.yaml' ) | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | } || eval { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
eval {
do {
File::ShareDir::module_file('Net::CIDR::MobileJP', 'cidr.yaml')
}
} || eval {
do {
File::ShareDir::dist_file('Net-CIDR-MobileJP', 'cidr.yaml')
}
}
MC/DC0%0/2
eval {
do {
File::ShareDir::module_file('Net::CIDR::MobileJP', 'cidr.yaml')
}
} || eval {
do {
File::ShareDir::dist_file('Net-CIDR-MobileJP', 'cidr.yaml')
}
}
eval {
do {
File::ShareDir::module_file('Net::CIDR::MobileJP', 'cidr.yaml')
}
}
eval {
do {
File::ShareDir::dist_file('Net-CIDR-MobileJP', 'cidr.yaml')
}
}
Truth table0%0/3
A || B
A= eval {
do {
File::ShareDir::module_file('Net::CIDR::MobileJP', 'cidr.yaml')
}
}B= eval {
do {
File::ShareDir::dist_file('Net-CIDR-MobileJP', 'cidr.yaml')
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | File::ShareDir::dist_file( 'Net-CIDR-MobileJP', 'cidr.yaml' ) | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | die $@ unless $file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $data = $yaml_loader->($file); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | sub get_carrier { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_carrier: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | my ($self, $ip) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | my ($carrier,) = map { keys %$_ } values %{$self->{spanner}->find($ip)}; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | ▶ | return $carrier || 'N'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$carrier || 'N'
MC/DC100%1/1
$carrier || 'N'
$carrier
Truth table100%2/2
A
A= $carrier
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||