| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Geo::Location::IP::Network; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later |
|
4
|
|
|
|
|
|
|
|
|
5
|
21
|
|
|
21
|
|
134841
|
use 5.026; |
|
|
21
|
|
|
|
|
71
|
|
|
6
|
21
|
|
|
21
|
|
112
|
use warnings; |
|
|
21
|
|
|
|
|
56
|
|
|
|
21
|
|
|
|
|
986
|
|
|
7
|
21
|
|
|
21
|
|
94
|
use utf8; |
|
|
21
|
|
|
|
|
36
|
|
|
|
21
|
|
|
|
|
138
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
21
|
|
|
21
|
|
1108
|
use Object::Pad; |
|
|
21
|
|
|
|
|
11478
|
|
|
|
21
|
|
|
|
|
121
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
class Geo::Location::IP::Network; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.005; |
|
14
|
|
|
|
|
|
|
|
|
15
|
21
|
|
|
21
|
|
7984
|
use Scalar::Util qw(); |
|
|
21
|
|
|
|
|
44
|
|
|
|
21
|
|
|
|
|
487
|
|
|
16
|
21
|
|
|
21
|
|
12660
|
use Socket qw(); |
|
|
21
|
|
|
|
|
165508
|
|
|
|
21
|
|
|
|
|
24032
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
5
|
|
|
5
|
1
|
2957
|
field $network_address :reader; |
|
|
5
|
|
|
|
|
38
|
|
|
19
|
2
|
|
|
2
|
1
|
11
|
field $prefixlen :param :reader; |
|
|
2
|
|
|
|
|
13
|
|
|
20
|
47
|
|
|
47
|
1
|
662
|
field $version :reader; |
|
|
47
|
|
|
|
|
271
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
1
|
1013
|
method with_prefixlen () { |
|
|
8
|
|
|
|
|
59
|
|
|
|
8
|
|
|
|
|
19
|
|
|
23
|
8
|
100
|
|
|
|
36
|
if (defined $network_address) { |
|
24
|
6
|
|
|
|
|
41
|
return $network_address . '/' . $prefixlen; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
2
|
|
|
|
|
13
|
return; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#<<< |
|
30
|
|
|
|
|
|
|
ADJUST :params (:$address) { |
|
31
|
|
|
|
|
|
|
if (defined $address && defined $prefixlen && $prefixlen >= 0) { |
|
32
|
|
|
|
|
|
|
if ($prefixlen <= 32 && index($address, '.') >= 0) { |
|
33
|
|
|
|
|
|
|
my $family = Socket::AF_INET; |
|
34
|
|
|
|
|
|
|
my $packed_address = Socket::inet_pton($family, $address); |
|
35
|
|
|
|
|
|
|
if (defined $packed_address) { |
|
36
|
|
|
|
|
|
|
my $packed_mask = ~pack 'N', (1 << (32 - $prefixlen)) - 1; |
|
37
|
|
|
|
|
|
|
$network_address = Socket::inet_ntop($family, |
|
38
|
|
|
|
|
|
|
$packed_address & $packed_mask); |
|
39
|
|
|
|
|
|
|
$version = 4; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif ($prefixlen <= 128 && index($address, ':') >= 0) { |
|
43
|
|
|
|
|
|
|
my $family = Socket::AF_INET6; |
|
44
|
|
|
|
|
|
|
my $packed_address = Socket::inet_pton($family, $address); |
|
45
|
|
|
|
|
|
|
if (defined $packed_address) { |
|
46
|
|
|
|
|
|
|
my $bits = '1' x $prefixlen . '0' x (128 - $prefixlen); |
|
47
|
|
|
|
|
|
|
my $packed_mask = pack 'B128', $bits; |
|
48
|
|
|
|
|
|
|
$network_address = Socket::inet_ntop($family, |
|
49
|
|
|
|
|
|
|
$packed_address & $packed_mask); |
|
50
|
|
|
|
|
|
|
$version = 6; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
#>>> |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use overload |
|
58
|
21
|
|
|
|
|
198
|
q{eq} => \&eq, |
|
59
|
21
|
|
|
21
|
|
12815
|
q{""} => \&stringify; |
|
|
21
|
|
|
|
|
44634
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub eq { |
|
62
|
4
|
|
|
4
|
0
|
2337
|
my ($self, $other) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
4
|
100
|
|
|
|
28
|
if (Scalar::Util::blessed($other)) { |
|
65
|
1
|
50
|
|
|
|
8
|
if ($other->isa(__PACKAGE__)) { |
|
66
|
1
|
|
|
|
|
6
|
return $self->with_prefixlen eq $other->with_prefixlen; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
3
|
|
|
|
|
14
|
return $self->with_prefixlen eq $other; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub stringify { |
|
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self->with_prefixlen; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
|
79
|
|
|
|
|
|
|
__END__ |