line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::CIDR::MobileJP; |
2
|
4
|
|
|
4
|
|
133854
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
149
|
|
3
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
427
|
|
4
|
4
|
|
|
4
|
|
91
|
use 5.00800; |
|
4
|
|
|
|
|
50
|
|
|
4
|
|
|
|
|
169
|
|
5
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
391
|
|
6
|
4
|
|
|
4
|
|
4722
|
use Net::CIDR::Lite; |
|
4
|
|
|
|
|
20005
|
|
|
4
|
|
|
|
|
111
|
|
7
|
4
|
|
|
4
|
|
3738
|
use File::ShareDir (); |
|
4
|
|
|
|
|
30446
|
|
|
4
|
|
|
|
|
391
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.24'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $yaml_loader; |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
|
|
|
|
|
|
$yaml_loader = sub { |
13
|
|
|
|
|
|
|
## no critic |
14
|
4
|
50
|
|
4
|
|
345
|
if (eval "use YAML::Syck; 1;") { |
|
4
|
|
|
|
|
1952
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
15
|
0
|
|
|
|
|
0
|
\&YAML::Syck::LoadFile; |
16
|
|
|
|
|
|
|
} else { |
17
|
4
|
|
|
|
|
3878
|
require YAML; |
18
|
4
|
|
|
|
|
56699
|
\&YAML::LoadFile; |
19
|
|
|
|
|
|
|
} |
20
|
4
|
|
|
4
|
|
25
|
}->(); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
3
|
|
|
3
|
1
|
13095
|
my ($class, $stuff) = @_; |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
17
|
return bless {spanner => $class->_create_spanner($class->_load_config($stuff))}, $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _create_spanner { |
30
|
3
|
|
|
3
|
|
12
|
my ($class, $conf) = @_; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
38
|
my $spanner = Net::CIDR::Lite::Span->new; |
33
|
3
|
|
|
|
|
108
|
while (my ($carrier, $ip_ranges) = each %$conf) { |
34
|
12
|
|
|
|
|
1404
|
$spanner->add(do { |
35
|
12
|
|
|
|
|
67
|
my $cidr = Net::CIDR::Lite->new; |
36
|
12
|
|
|
|
|
124
|
for my $ip_range (@$ip_ranges) { |
37
|
282
|
|
|
|
|
13508
|
$cidr->add($ip_range); |
38
|
|
|
|
|
|
|
} |
39
|
12
|
|
|
|
|
509
|
$cidr; |
40
|
|
|
|
|
|
|
}, $carrier); |
41
|
|
|
|
|
|
|
} |
42
|
3
|
|
|
|
|
630
|
return $spanner; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _load_config { |
46
|
3
|
|
|
3
|
|
7
|
my ($self, $stuff) = @_; |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
7
|
my $data; |
49
|
3
|
50
|
33
|
|
|
162
|
if (defined $stuff && -f $stuff && -r _) { |
|
|
0
|
33
|
|
|
|
|
50
|
|
|
|
|
|
|
# load yaml from file |
51
|
3
|
|
|
|
|
21
|
$data = $yaml_loader->($stuff); |
52
|
|
|
|
|
|
|
} elsif ($stuff) { |
53
|
|
|
|
|
|
|
# raw data |
54
|
0
|
|
|
|
|
0
|
$data = $stuff; |
55
|
|
|
|
|
|
|
} else { |
56
|
|
|
|
|
|
|
# generated file |
57
|
|
|
|
|
|
|
my $file = eval { |
58
|
|
|
|
|
|
|
# use module_file first, this is needed by backward-compatibility |
59
|
|
|
|
|
|
|
File::ShareDir::module_file( 'Net::CIDR::MobileJP', 'cidr.yaml' ) |
60
|
0
|
|
0
|
|
|
0
|
} || eval { |
61
|
|
|
|
|
|
|
File::ShareDir::dist_file( 'Net-CIDR-MobileJP', 'cidr.yaml' ) |
62
|
|
|
|
|
|
|
}; |
63
|
0
|
0
|
|
|
|
0
|
die $@ unless $file; |
64
|
0
|
|
|
|
|
0
|
$data = $yaml_loader->($file); |
65
|
|
|
|
|
|
|
} |
66
|
3
|
|
|
|
|
159306
|
return $data; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_carrier { |
70
|
3
|
|
|
3
|
1
|
88
|
my ($self, $ip) = @_; |
71
|
|
|
|
|
|
|
|
72
|
3
|
|
|
|
|
8
|
my ($carrier,) = map { keys %$_ } values %{$self->{spanner}->find($ip)}; |
|
3
|
|
|
|
|
3371
|
|
|
3
|
|
|
|
|
27
|
|
73
|
3
|
|
100
|
|
|
38
|
return $carrier || 'N'; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |