line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
3
|
|
1774
|
use 5.008; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
116
|
|
11
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
109
|
|
12
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
98
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Net::IP::Identifier_Role; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
12
|
use Role::Tiny; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
18
|
|
17
|
3
|
|
|
3
|
|
2219
|
use Net::IP; |
|
3
|
|
|
|
|
88727
|
|
|
3
|
|
|
|
|
565
|
|
18
|
3
|
|
|
3
|
|
1298
|
use Net::IP::Identifier::Net; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
250
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.110'; # VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
requires qw( new name ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use overload ( |
25
|
3
|
|
|
|
|
21
|
'""' => 'name', |
26
|
3
|
|
|
3
|
|
18
|
); |
|
3
|
|
|
|
|
4
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub ips { |
29
|
132
|
|
|
132
|
1
|
12043
|
my ($self, @new) = @_; |
30
|
|
|
|
|
|
|
|
31
|
132
|
100
|
|
|
|
589
|
if (@_ > 1) { |
32
|
66
|
|
|
|
|
217
|
for (my $ii = 0; $ii < @new; $ii++) { |
33
|
1268
|
|
|
|
|
23120
|
my $cidr = $new[$ii]; |
34
|
1268
|
|
|
|
|
1212
|
my $ip; |
35
|
1268
|
50
|
|
|
|
2221
|
if (ref $cidr) { # already a Net::IP or Net::IP::Identifier::Net |
36
|
0
|
|
|
|
|
0
|
$ip = $cidr; |
37
|
0
|
0
|
|
|
|
0
|
if (ref $ip eq 'Net::IP') { |
38
|
|
|
|
|
|
|
# convert Net::IP to Net::IP::Identifier::Net |
39
|
0
|
|
|
|
|
0
|
$ip = Net::IP::Identifier::Net->new($ip); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
1268
|
100
|
66
|
|
|
10212
|
if (defined $new[$ii + 1] and |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
44
|
|
|
|
|
|
|
not ref $new[$ii + 1] and |
45
|
|
|
|
|
|
|
$new[$ii + 1] eq '-' and |
46
|
|
|
|
|
|
|
defined $new[$ii + 2]) { |
47
|
1
|
|
|
|
|
3
|
$cidr = "$cidr - $new[$ii + 2]"; |
48
|
1
|
|
|
|
|
2
|
$ii += 2; |
49
|
|
|
|
|
|
|
} |
50
|
1268
|
|
|
|
|
4539
|
$ip = Net::IP::Identifier::Net->new($cidr) |
51
|
|
|
|
|
|
|
} |
52
|
1268
|
50
|
|
|
|
3561
|
$self->{ips}{"$ip"} = $ip if ($ip); # stringify $ip for key |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return wantarray |
57
|
132
|
100
|
|
|
|
4392
|
? values %{$self->{ips}} |
|
66
|
|
|
|
|
1084
|
|
58
|
|
|
|
|
|
|
: $self->{ips}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub cidrs { |
62
|
0
|
|
|
0
|
1
|
0
|
my ($self, @new) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return wantarray |
65
|
0
|
0
|
|
|
|
0
|
? keys %{$self->{ips}} |
|
0
|
|
|
|
|
0
|
|
66
|
|
|
|
|
|
|
: $self->{ips}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub identify { |
70
|
0
|
|
|
0
|
1
|
0
|
my ($self, $ip, $replacement) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
0
|
$ip = Net::IP::Identifier::Net->new($ip) if (not ref $ip); |
73
|
0
|
|
|
|
|
0
|
for my $net (values %{$self->ips}) { |
|
0
|
|
|
|
|
0
|
|
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
|
0
|
|
|
|
0
|
next if ($net->version ne $ip->version); |
77
|
0
|
|
|
|
|
0
|
my $overlap = $ip->overlaps($net); |
78
|
0
|
0
|
0
|
|
|
0
|
if ($overlap == $IP_IDENTICAL or |
79
|
|
|
|
|
|
|
$overlap == $IP_A_IN_B_OVERLAP) { |
80
|
0
|
0
|
|
|
|
0
|
return $net if ($self->cidr_id); |
81
|
0
|
|
0
|
|
|
0
|
return $replacement || $self; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
0
|
return; # undef, doesn't belong to entity |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub cidr_id { |
88
|
0
|
|
|
0
|
1
|
0
|
my ($self, @new) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
0
|
if (@_ > 1) { |
91
|
0
|
|
|
|
|
0
|
$self->{cidr_id} = $new[0]; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
0
|
return $self->{cidr_id}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
1
|
0
|
sub refresh { |
97
|
|
|
|
|
|
|
# stub, may be overridden by entities to refresh the ips array |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
35
|
|
|
35
|
0
|
276
|
sub children { |
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
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |