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
|
2
|
|
|
2
|
|
1461
|
use 5.008; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
96
|
|
11
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
12
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
98
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Net::IP::Identifier_Role; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
9
|
use Role::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
17
|
2
|
|
|
2
|
|
4701
|
use Net::IP; |
|
2
|
|
|
|
|
112466
|
|
|
2
|
|
|
|
|
642
|
|
18
|
2
|
|
|
2
|
|
1161
|
use Net::IP::Identifier::Net; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
170
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.106'; # VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
requires qw( new name ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use overload ( |
25
|
2
|
|
|
|
|
10
|
'""' => 'name', |
26
|
2
|
|
|
2
|
|
12
|
); |
|
2
|
|
|
|
|
3
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub ips { |
29
|
3
|
|
|
3
|
1
|
7217
|
my ($self, @new) = @_; |
30
|
|
|
|
|
|
|
|
31
|
3
|
50
|
|
|
|
17
|
if (@_ > 1) { |
32
|
3
|
|
|
|
|
13
|
for (my $ii = 0; $ii < @new; $ii++) { |
33
|
6
|
|
|
|
|
253
|
my $cidr = $new[$ii]; |
34
|
6
|
|
|
|
|
10
|
my $ip; |
35
|
6
|
50
|
|
|
|
20
|
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
|
6
|
100
|
66
|
|
|
74
|
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
|
|
|
|
|
5
|
$cidr = "$cidr - $new[$ii + 2]"; |
48
|
1
|
|
|
|
|
3
|
$ii += 2; |
49
|
|
|
|
|
|
|
} |
50
|
6
|
|
|
|
|
41
|
$ip = Net::IP::Identifier::Net->new($cidr) |
51
|
|
|
|
|
|
|
} |
52
|
6
|
50
|
|
|
|
21
|
$self->{ips}{"$ip"} = $ip if ($ip); # stringify $ip for key |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return wantarray |
57
|
3
|
50
|
|
|
|
73
|
? values %{$self->{ips}} |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
: $self->{ips}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub cidrs { |
62
|
0
|
|
|
0
|
1
|
|
my ($self, @new) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return wantarray |
65
|
0
|
0
|
|
|
|
|
? keys %{$self->{ips}} |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
: $self->{ips}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub identify { |
70
|
0
|
|
|
0
|
1
|
|
my ($self, $ip, $replacement) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
$ip = Net::IP::Identifier::Net->new($ip) if (not ref $ip); |
73
|
0
|
|
|
|
|
|
for my $net (values %{$self->ips}) { |
|
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
|
|
|
|
|
next if ($net->version ne $ip->version); |
77
|
0
|
|
|
|
|
|
my $overlap = $ip->overlaps($net); |
78
|
0
|
0
|
0
|
|
|
|
if ($overlap == $IP_IDENTICAL or |
79
|
|
|
|
|
|
|
$overlap == $IP_A_IN_B_OVERLAP) { |
80
|
0
|
0
|
|
|
|
|
return $net if ($self->cidr_id); |
81
|
0
|
|
0
|
|
|
|
return $replacement || $self; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
return; # undef, doesn't belong to entity |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub cidr_id { |
88
|
0
|
|
|
0
|
1
|
|
my ($self, @new) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if (@_ > 1) { |
91
|
0
|
|
|
|
|
|
$self->{cidr_id} = $new[0]; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
return $self->{cidr_id}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
1
|
|
sub refresh { |
97
|
|
|
|
|
|
|
# stub, may be overridden by entities to refresh the ips array |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
0
|
0
|
|
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__ |