Identifier_Role.pm

filter: Statementstmt 64.2% 36 / 56 Branchbran 38.4% 10 / 26 Conditioncond 46.6% 7 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 69.2% 9 / 13 Podpod 83.3% 5 / 6 totaltotal 55.6% 69 / 124 SCAR 40.5
CC
20
Cov
55%
identify
72.0
ips
12.5
cidrs
6.0
CRAP 57.3
« Identifier/Binode.pm ↑ Summary Identifier/Net.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.110'; # VERSION
21  
22 3 requires qw( new name );
23  
24 use overload (
25 3 '""' => 'name',
26 3 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub ips {
29 132 ▶ my ($self, @new) = @_;
Subroutine ips: called CC=11 SCAR=25.2
Pod documented
30  
31 132 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 66 66 132
32 66 ▶ for (my $ii = 0; $ii < @new; $ii++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ii < @new) 1268 66 1334
33 1268 my $cidr = $new[$ii];
34 1268 my $ip;
35 1268 ▶ if (ref $cidr) { # already a Net::IP or Net::IP::Identifier::Net
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cidr) { } 0 1268 1268
36 0 $ip = $cidr;
37 0 ▶ if (ref $ip eq 'Net::IP') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ip eq "Net::IP") 0 0 0
38 # convert Net::IP to Net::IP::Identifier::Net
39 0 $ip = Net::IP::Identifier::Net->new($ip);
40 }
41 }
42 else {
43 1268 ▶ 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 1267 1268
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
126701
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-"
!ll&&!rl&&r
6612011
defined $new[$ii + 1] and not ref $new[$ii + 1]
!ll&&!rl&&r
6601202
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
44 not ref $new[$ii + 1] and
45 $new[$ii + 1] eq '-' and
46 defined $new[$ii + 2]) {
47 1 $cidr = "$cidr - $new[$ii + 2]";
48 1 $ii += 2;
49 }
50 1268 $ip = Net::IP::Identifier::Net->new($cidr)
51 }
52 1268 ▶ $self->{ips}{"$ip"} = $ip if ($ip); # stringify $ip for key
Branch: 1 branch
BranchTrueFalseTotal
if $ip 1268 0 1268
53 }
54 }
55  
56 return wantarray
57 66 ? values %{$self->{ips}}
58 132 ▶ : $self->{ips};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 66 66 132
59 }
60  
61 sub cidrs {
62 0 ▶ my ($self, @new) = @_;
Subroutine cidrs: not called CC=2 SCAR=17.9
Pod documented
63  
64 return wantarray
65 0 ? keys %{$self->{ips}}
66 0 ▶ : $self->{ips};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
67 }
68  
69 sub identify {
70 0 ▶ my ($self, $ip, $replacement) = @_;
Subroutine identify: not called CC=8 SCAR=42.8
Pod documented
71  
72 0 ▶ $ip = Net::IP::Identifier::Net->new($ip) if (not ref $ip);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ip 0 0 0
73 0 for my $net (values %{$self->ips}) {
74 # if different versions, can't be overlap (unless entity gets
75 # some ::ffff:N:N:N:N/N blocks which seems unlikly)
76 0 ▶ next if ($net->version ne $ip->version);
Branch: 1 branch
BranchTrueFalseTotal
if $net->version ne $ip->version 0 0 0
77 0 my $overlap = $ip->overlaps($net);
78 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
79 $overlap == $IP_A_IN_B_OVERLAP) {
80 0 ▶ return $net if ($self->cidr_id);
Branch: 1 branch
BranchTrueFalseTotal
if $self->cidr_id 0 0 0
81 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
82 }
83 }
84 0 return; # undef, doesn't belong to entity
85 }
86  
87 sub cidr_id {
88 0 ▶ my ($self, @new) = @_;
Subroutine cidr_id: not called CC=2 SCAR=17.9
Pod documented
89  
90 0 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
91 0 $self->{cidr_id} = $new[0];
92 }
93 0 return $self->{cidr_id};
94 }
95  
96 ▶sub refresh {
Subroutine refresh: not called CC=1 SCAR=0.0
Pod documented
97 # stub, may be overridden by entities to refresh the ips array
98 }
99  
100 ▶sub children {
Subroutine children: called CC=1 SCAR=0.0
Pod undocumented
101 # stub, entities with children should return an array of the names here
102 # (and the child netblocks should not be listed in the parent)
103 }
104  
105 3 1;
106  
107 __END__
« Identifier/Binode.pm ↑ Summary Identifier/Net.pm »