Identifier_Role.pm

filter: Statementstmt 62.5% 35 / 56 Branchbran 30.7% 8 / 26 Conditioncond 46.6% 7 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 61.5% 8 / 13 Podpod 83.3% 5 / 6 totaltotal 52.4% 65 / 124 CC 20 SCAR 31.8
CC
20
Cov
52%
identify
72.0
ips
14.5
cidrs
6.0
CRAP 24.0
« Identifier/Net.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 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 package Net::IP::Identifier_Role;
15  
16 2 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Net::IP::Identifier::Net;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 our $VERSION = '0.106'; # VERSION
21  
22 2 requires qw( new name );
23  
24 use overload (
25 2 '""' => 'name',
26 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 sub ips {
29 3 ▶ my ($self, @new) = @_;
Subroutine ips: called CC=11 SCAR=26.8
Pod documented
30  
31 3 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 3 0 3
32 3 ▶ for (my $ii = 0; $ii < @new; $ii++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ii < @new) 6 3 9
33 6 my $cidr = $new[$ii];
34 6 my $ip;
35 6 ▶ if (ref $cidr) { # already a Net::IP or Net::IP::Identifier::Net
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cidr) { } 0 6 6
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 6 ▶ 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 5 6
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
501
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-"
!ll&&!rl&&r
321
defined $new[$ii + 1] and not ref $new[$ii + 1]
!ll&&!rl&&r
303
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 6 $ip = Net::IP::Identifier::Net->new($cidr)
51 }
52 6 ▶ $self->{ips}{"$ip"} = $ip if ($ip); # stringify $ip for key
Branch: 1 branch
BranchTrueFalseTotal
if $ip 6 0 6
53 }
54 }
55  
56 return wantarray
57 0 ? values %{$self->{ips}}
58 3 ▶ : $self->{ips};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
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: not 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 2 1;
106  
107 __END__
« Identifier/Net.pm ↑ Summary Identifier/Binode.pm »