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
|
|
2034
|
use 5.008; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
132
|
|
11
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
122
|
|
12
|
3
|
|
|
3
|
|
22
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
140
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Net::IP::Identifier_Role; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
15
|
use Role::Tiny; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
27
|
|
17
|
3
|
|
|
3
|
|
2375
|
use Net::IP; |
|
3
|
|
|
|
|
94691
|
|
|
3
|
|
|
|
|
672
|
|
18
|
3
|
|
|
3
|
|
1496
|
use Net::IP::Identifier::Net; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
290
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.111'; # VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
requires qw( new name ); |
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
19
|
use overload '""' => sub { shift->name }; |
|
3
|
|
|
147
|
|
4
|
|
|
3
|
|
|
|
|
25
|
|
|
147
|
|
|
|
|
941
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ips { |
27
|
132
|
|
|
132
|
1
|
8093
|
my ($self, @new) = @_; |
28
|
|
|
|
|
|
|
|
29
|
132
|
100
|
|
|
|
456
|
if (@_ > 1) { |
30
|
65
|
|
|
|
|
204
|
for (my $ii = 0; $ii < @new; $ii++) { |
31
|
1264
|
|
|
|
|
17851
|
my $cidr = $new[$ii]; |
32
|
1264
|
|
|
|
|
1072
|
my $ip; |
33
|
1264
|
50
|
|
|
|
1961
|
if (ref $cidr) { # already a Net::IP or Net::IP::Identifier::Net |
34
|
0
|
|
|
|
|
0
|
$ip = $cidr; |
35
|
0
|
0
|
|
|
|
0
|
if (ref $ip eq 'Net::IP') { |
36
|
|
|
|
|
|
|
# convert Net::IP to Net::IP::Identifier::Net |
37
|
0
|
|
|
|
|
0
|
$ip = Net::IP::Identifier::Net->new($ip); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
1264
|
100
|
66
|
|
|
8099
|
if (defined $new[$ii + 1] and |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
42
|
|
|
|
|
|
|
not ref $new[$ii + 1] and |
43
|
|
|
|
|
|
|
$new[$ii + 1] eq '-' and |
44
|
|
|
|
|
|
|
defined $new[$ii + 2]) { |
45
|
1
|
|
|
|
|
5
|
$cidr = "$cidr - $new[$ii + 2]"; |
46
|
1
|
|
|
|
|
2
|
$ii += 2; |
47
|
|
|
|
|
|
|
} |
48
|
1264
|
|
|
|
|
3503
|
$ip = Net::IP::Identifier::Net->new($cidr) |
49
|
|
|
|
|
|
|
} |
50
|
1264
|
50
|
|
|
|
3037
|
$self->{ips}{"$ip"} = $ip if ($ip); # stringify $ip for key |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return wantarray |
55
|
132
|
100
|
|
|
|
3569
|
? values %{$self->{ips}} |
|
66
|
|
|
|
|
1042
|
|
56
|
|
|
|
|
|
|
: $self->{ips}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub cidrs { |
60
|
0
|
|
|
0
|
1
|
0
|
my ($self, @new) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return wantarray |
63
|
0
|
0
|
|
|
|
0
|
? keys %{$self->{ips}} |
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
: $self->{ips}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub identify { |
68
|
0
|
|
|
0
|
1
|
0
|
my ($self, $ip, $replacement) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
0
|
$ip = Net::IP::Identifier::Net->new($ip) if (not ref $ip); |
71
|
0
|
|
|
|
|
0
|
for my $net (values %{$self->ips}) { |
|
0
|
|
|
|
|
0
|
|
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
|
0
|
|
|
|
0
|
next if ($net->version ne $ip->version); |
75
|
0
|
|
|
|
|
0
|
my $overlap = $ip->overlaps($net); |
76
|
0
|
0
|
0
|
|
|
0
|
if ($overlap == $IP_IDENTICAL or |
77
|
|
|
|
|
|
|
$overlap == $IP_A_IN_B_OVERLAP) { |
78
|
0
|
0
|
|
|
|
0
|
return $net if ($self->cidr_id); |
79
|
0
|
|
0
|
|
|
0
|
return $replacement || $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
0
|
return; # undef, doesn't belong to entity |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub cidr_id { |
86
|
0
|
|
|
0
|
1
|
0
|
my ($self, @new) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
0
|
if (@_ > 1) { |
89
|
0
|
|
|
|
|
0
|
$self->{cidr_id} = $new[0]; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
0
|
return $self->{cidr_id}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
0
|
sub refresh { |
95
|
|
|
|
|
|
|
# stub, may be overridden by entities to refresh the ips array |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
35
|
|
|
35
|
0
|
169
|
sub children { |
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
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |