| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 65 | ▶ | for (my $ii = 0; $ii < @new; $ii++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $ip = $cidr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if (ref $ip eq 'Net::IP') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition77%7/9
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-" and defined $new[$ii + 2]
defined $new[$ii + 1] and not ref $new[$ii + 1] and $new[$ii + 1] eq "-"
defined $new[$ii + 1] and not ref $new[$ii + 1]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 66 | ? values %{$self->{ips}} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 132 | ▶ | : $self->{ips}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $overlap = $ip->overlaps($net); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($overlap == $IP_IDENTICAL or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$overlap == $Net::IP::Identifier_Role::IP_IDENTICAL or $overlap == $Net::IP::Identifier_Role::IP_A_IN_B_OVERLAP
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $overlap == $IP_A_IN_B_OVERLAP) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return $net if ($self->cidr_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return $replacement || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$replacement || $self
MC/DC0%0/2
$replacement || $self
$replacement
$self
Truth table0%0/3
A || B
A= $replacementB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||