Identifier_Role.pm

filter: Statementstmt 64.9% 37 / 57 Branchbran 38.4% 10 / 26 Conditioncond 46.6% 7 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 71.4% 10 / 14 Podpod 83.3% 5 / 6 totaltotal 56.3% 71 / 126 CC 20 SCAR 31.2
CC
20
Cov
55%
identify
72.0
ips
12.5
cidrs
6.0
CRAP 22.6
« Identifier.pm ↑ Summary Identifier/Binode.pm »
1 #===============================================================================
2 # PODNAME: Net::IP::Identifier_Role
3 # ABSTRACT: The role that Net::IP::Identifier plugins must satisfy
4 #
5 # AUTHOR: Reid Augustin (REID)
6 # EMAIL: reid@hellosix.com
7 # CREATED: Mon Oct 6 12:25:04 PDT 2014
8 #===============================================================================
9  
10 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 package Net::IP::Identifier_Role;
15  
16 3 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Net::IP::Identifier::Net;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 our $VERSION = '0.111'; # VERSION
21  
22 3 requires qw( new name );
23  
24 3 ▶use overload '""' => sub { shift->name };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 132 ▶sub ips {
Subroutine ips: called CC=11 SCAR=25.2
Pod documented
27 132 my ($self, @new) = @_;
28  
29 132 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 65 67 132
30 65 ▶ for (my $ii = 0; $ii < @new; $ii++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ii < @new) 1264 65 1329
31 1264 my $cidr = $new[$ii];
32 1264 my $ip;
33 1264 ▶ if (ref $cidr) { # already a Net::IP or Net::IP::Identifier::Net
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cidr) { } 0 1264 1264
34 0 $ip = $cidr;
35 0 ▶ if (ref $ip eq 'Net::IP') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ip eq "Net::IP") 0 0 0
36 # convert Net::IP to Net::IP::Identifier::Net
37 0 $ip = Net::IP::Identifier::Net->new($ip);
38 }
39 }
40 else {
41 1264 ▶ if (defined $new[$ii + 1] and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-" and defined $new[$ii + 2]) 1 1263 1264
Condition77%7/9
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-" and defined $new[$ii + 2]
!ll&&!rl&&r
126301
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-"
!ll&&!rl&&r
6511981
defined $new[$ii + 1] and not ref $new[$ii + 1]
!ll&&!rl&&r
6501199
MC/DC50%2/4
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-" and defined $new[$ii + 2]
defined $new[$ii + 1] not ref $new[$ii + 1] $new[$ii + 1] eq "-" defined $new[$ii + 2]
Truth table60%3/5
A and not(B) and C and D
A= defined $new[$ii + 1]B= not ref $new[$ii + 1]C= $new[$ii + 1] eq "-"D= defined $new[$ii + 2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
42 not ref $new[$ii + 1] and
43 $new[$ii + 1] eq '-' and
44 defined $new[$ii + 2]) {
45 1 $cidr = "$cidr - $new[$ii + 2]";
46 1 $ii += 2;
47 }
48 1264 $ip = Net::IP::Identifier::Net->new($cidr)
49 }
50 1264 ▶ $self->{ips}{"$ip"} = $ip if ($ip); # stringify $ip for key
Branch: 1 branch
BranchTrueFalseTotal
if $ip 1264 0 1264
51 }
52 }
53  
54 return wantarray
55 66 ? values %{$self->{ips}}
56 132 ▶ : $self->{ips};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 66 66 132
57 }
58  
59 0 ▶sub cidrs {
Subroutine cidrs: not called CC=2 SCAR=17.9
Pod documented
60 0 my ($self, @new) = @_;
61  
62 return wantarray
63 0 ? keys %{$self->{ips}}
64 0 ▶ : $self->{ips};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
65 }
66  
67 0 ▶sub identify {
Subroutine identify: not called CC=8 SCAR=42.8
Pod documented
68 0 my ($self, $ip, $replacement) = @_;
69  
70 0 ▶ $ip = Net::IP::Identifier::Net->new($ip) if (not ref $ip);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ip 0 0 0
71 0 for my $net (values %{$self->ips}) {
72 # if different versions, can't be overlap (unless entity gets
73 # some ::ffff:N:N:N:N/N blocks which seems unlikly)
74 0 ▶ next if ($net->version ne $ip->version);
Branch: 1 branch
BranchTrueFalseTotal
if $net->version ne $ip->version 0 0 0
75 0 my $overlap = $ip->overlaps($net);
76 0 ▶ if ($overlap == $IP_IDENTICAL or
Branch: 1 branch
BranchTrueFalseTotal
if ($overlap == $Net::IP::Identifier_Role::IP_IDENTICAL or $overlap == $Net::IP::Identifier_Role::IP_A_IN_B_OVERLAP) 0 0 0
Condition0%0/3
$overlap == $Net::IP::Identifier_Role::IP_IDENTICAL or $overlap == $Net::IP::Identifier_Role::IP_A_IN_B_OVERLAP
l!l&&r!l&&!r
000
MC/DC0%0/2
$overlap == $Net::IP::Identifier_Role::IP_IDENTICAL or $overlap == $Net::IP::Identifier_Role::IP_A_IN_B_OVERLAP
$overlap == $Net::IP::Identifier_Role::IP_IDENTICAL $overlap == $Net::IP::Identifier_Role::IP_A_IN_B_OVERLAP
Truth table0%0/3
A or B
A= $overlap == $Net::IP::Identifier_Role::IP_IDENTICALB= $overlap == $Net::IP::Identifier_Role::IP_A_IN_B_OVERLAP
ABresult
1X1
011
000
77 $overlap == $IP_A_IN_B_OVERLAP) {
78 0 ▶ return $net if ($self->cidr_id);
Branch: 1 branch
BranchTrueFalseTotal
if $self->cidr_id 0 0 0
79 0 ▶ return $replacement || $self;
Condition0%0/3
$replacement || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
$replacement || $self
$replacement $self
Truth table0%0/3
A || B
A= $replacementB= $self
ABresult
1X1
011
000
80 }
81 }
82 0 return; # undef, doesn't belong to entity
83 }
84  
85 0 ▶sub cidr_id {
Subroutine cidr_id: not called CC=2 SCAR=17.9
Pod documented
86 0 my ($self, @new) = @_;
87  
88 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
89 0 $self->{cidr_id} = $new[0];
90 }
91 0 return $self->{cidr_id};
92 }
93  
94 0 ▶sub refresh {
Subroutine refresh: not called CC=1 SCAR=0.0
Pod documented
95 # stub, may be overridden by entities to refresh the ips array
96 }
97  
98 35 ▶sub children {
Subroutine children: called CC=1 SCAR=0.0
Pod undocumented
99 # stub, entities with children should return an array of the names here
100 # (and the child netblocks should not be listed in the parent)
101 }
102  
103 3 1;
104  
105 __END__
« Identifier.pm ↑ Summary Identifier/Binode.pm »