MobileJP.pm

filter: Statementstmt 83.6% 46 / 55 Branchbran 40.0% 4 / 10 Conditioncond 36.3% 4 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 72.1% 70 / 97 CC 11 SCAR 21.1
CC
11
Cov
71%
_load_config
23.3
_create_spanner
3.0
__ANON__
2.4
CRAP 8.2
↑ Summary net-cidr-mobilejp-scraper.pl »
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
BranchTrueFalseTotal
if (eval 'use YAML::Syck; 1;') { } 0 4 4
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
BranchTrueFalseTotal
if (() = each %$conf) 12 3 15
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
BranchTrueFalseTotal
if (defined $stuff and -f $stuff and -r _) { } 3 0 3
elsif ($stuff) { } 0 0 0
Condition33%2/6
defined $stuff and -f $stuff and -r _
!ll&&!rl&&r
003
defined $stuff and -f $stuff
!ll&&!rl&&r
003
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 _
ABCresult
0XX0
10X0
1100
1111
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') } }
l!l&&r!l&&!r
000
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') } }
ABresult
1X1
011
000
61 0 File::ShareDir::dist_file( 'Net-CIDR-MobileJP', 'cidr.yaml' )
62 };
63 0 ▶ die $@ unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
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'
l!l
21
MC/DC100%1/1
$carrier || 'N'
$carrier
Truth table100%2/2
A
A= $carrier
Aresult
11
00
74 }
75  
76  
77 4 1;
78 __END__
↑ Summary net-cidr-mobilejp-scraper.pl »