line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::RIR_CC; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
75775
|
use Mouse; |
|
2
|
|
|
|
|
113082
|
|
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
3107
|
use File::ShareDir qw(dist_file); |
|
2
|
|
|
|
|
15403
|
|
|
2
|
|
|
|
|
206
|
|
5
|
2
|
|
|
2
|
|
2406
|
use HTML::TableExtract; |
|
2
|
|
|
|
|
54845
|
|
|
2
|
|
|
|
|
17
|
|
6
|
2
|
|
|
2
|
|
1715
|
use Net::RIR_CC::RIR; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
7
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
119
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1446
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.06'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'datafile' => ( is => 'ro', isa => 'Str', default => sub { |
14
|
|
|
|
|
|
|
my $datafile = dist_file( 'Net-RIR_CC', 'list-of-country-codes-and-rirs-ordered-by-country-code.html' ); |
15
|
|
|
|
|
|
|
-f $datafile or die "Missing datafile '$datafile'\n"; |
16
|
|
|
|
|
|
|
return $datafile; |
17
|
|
|
|
|
|
|
} ); |
18
|
|
|
|
|
|
|
has 'table' => ( is => 'ro', lazy_build => 1 ); |
19
|
|
|
|
|
|
|
has 'cc_map' => ( is => 'ro', isa => 'HashRef', lazy_build => 1 ); |
20
|
|
|
|
|
|
|
has 'a3_map' => ( is => 'ro', isa => 'HashRef', lazy_build => 1 ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_table { |
23
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
11
|
my $te = HTML::TableExtract->new( headers => [ 'A 2', 'A 3', 'Region' ] ); |
26
|
1
|
|
|
|
|
215
|
$te->parse_file( $self->datafile ); |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
181950
|
die sprintf "Found %d tables in datafile, when expecting 1\n", scalar $te->tables |
29
|
|
|
|
|
|
|
if $te->tables != 1; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
18
|
return $te->first_table_found; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _map_table_with_key { |
35
|
2
|
|
|
2
|
|
5
|
my ($self, $key) = @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
4
|
my $map = {}; |
38
|
2
|
|
|
|
|
16
|
for my $row ($self->table->rows) { |
39
|
482
|
|
|
|
|
40485
|
my $value = $row->[$#$row]; |
40
|
482
|
100
|
|
|
|
802
|
next if ! defined $value; |
41
|
480
|
|
|
|
|
1041
|
$value =~ s/\sNCC$//; |
42
|
|
|
|
|
|
|
|
43
|
480
|
|
|
|
|
1396
|
$map->{ $row->[$key] } = $value; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
161
|
return $map; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _build_cc_map { |
50
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
my $data = $self->_map_table_with_key(0); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Add missing codes not covered by the NRO page |
55
|
1
|
|
|
|
|
4
|
$data->{RS} = 'RIPE'; # Serbia |
56
|
1
|
|
|
|
|
3
|
$data->{ME} = 'RIPE'; # Montenegro |
57
|
1
|
|
|
|
|
4
|
$data->{JE} = 'RIPE'; # Jersey |
58
|
1
|
|
|
|
|
2
|
$data->{GG} = 'RIPE'; # Guernsey |
59
|
1
|
|
|
|
|
4
|
$data->{IM} = 'RIPE'; # Isle of Man |
60
|
1
|
|
|
|
|
3
|
$data->{MF} = 'ARIN'; # Saint Martin |
61
|
1
|
|
|
|
|
2
|
$data->{SS} = 'AFRINIC'; # South Sudan |
62
|
1
|
|
|
|
|
3
|
$data->{BQ} = 'LACNIC'; # Bonaire, Sint Eustatius and Saba |
63
|
1
|
|
|
|
|
2
|
$data->{UK} = 'RIPE'; # GB is official ISO-3166-2 code |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Region codes |
66
|
1
|
|
|
|
|
3
|
$data->{EU} = 'RIPE'; # Europe |
67
|
1
|
|
|
|
|
3
|
$data->{AP} = 'APNIC'; # Asia-Pacific |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
22
|
return $data; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _build_a3_map { |
73
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
5
|
my $data = $self->_map_table_with_key(1); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Add missing codes not covered by the NRO page |
78
|
1
|
|
|
|
|
5
|
$data->{SRB} = 'RIPE'; # Serbia |
79
|
1
|
|
|
|
|
3
|
$data->{MNE} = 'RIPE'; # Montenegro |
80
|
1
|
|
|
|
|
2
|
$data->{JEY} = 'RIPE'; # Jersey |
81
|
1
|
|
|
|
|
3
|
$data->{GGY} = 'RIPE'; # Guernsey |
82
|
1
|
|
|
|
|
2
|
$data->{IMN} = 'RIPE'; # Isle of Man |
83
|
1
|
|
|
|
|
2
|
$data->{MAF} = 'ARIN'; # Saint Martin |
84
|
1
|
|
|
|
|
2
|
$data->{SSD} = 'AFRINIC'; # South Sudan |
85
|
1
|
|
|
|
|
3
|
$data->{BES} = 'LACNIC'; # Bonaire, Sint Eustatius and Saba |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
20
|
return $data; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub get_rir { |
91
|
36
|
|
|
36
|
0
|
15527
|
my ($self, $code) = @_; |
92
|
|
|
|
|
|
|
|
93
|
36
|
50
|
66
|
|
|
241
|
croak "Invalid code '$code' (not alpha2 or alpha3)" if length $code != 2 and length $code != 3; |
94
|
|
|
|
|
|
|
|
95
|
36
|
100
|
|
|
|
270
|
my $name = length $code == 2 ? $self->cc_map->{$code} : $self->a3_map->{$code} |
|
|
50
|
|
|
|
|
|
96
|
|
|
|
|
|
|
or croak "Invalid code '$code'"; |
97
|
|
|
|
|
|
|
|
98
|
36
|
|
|
|
|
461
|
return Net::RIR_CC::RIR->new( name => $name ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Net::RIR_CC - perl module for mapping country codes to RIRs |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 VERSION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Version 0.06 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
use Net::RIR_CC; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Constructor |
114
|
|
|
|
|
|
|
$rc = Net::RIR_CC->new; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Or with an explicit (updated) data file |
117
|
|
|
|
|
|
|
$rc = Net::RIR_CC->new(datafile => '/tmp/list-of-country-codes-and-rirs-ordered-by-country-code'); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Lookup an ISO-3166 alpha2 or alpha3 code, returning a Net::RIR_CC::RIR object |
120
|
|
|
|
|
|
|
$rir = $rc->get_rir('AU'); |
121
|
|
|
|
|
|
|
$rir = $rc->get_rir('NZL'); |
122
|
|
|
|
|
|
|
print $rir->name; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 DESCRIPTION |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Net::RIR_CC is a perl module for mapping ISO-3166 country codes to RIRs |
128
|
|
|
|
|
|
|
(Regional Internet Registries), using the mappings from |
129
|
|
|
|
|
|
|
L, |
130
|
|
|
|
|
|
|
plus a few extras missing from that page. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
A snapshot of this page is included with the distribution, but you can |
133
|
|
|
|
|
|
|
download and load an updated version if you'd prefer. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 AUTHOR |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Gavin Carr, C<< >> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 BUGS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
142
|
|
|
|
|
|
|
or through the web interface at L. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright 2013 Gavin Carr. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
149
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
150
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
157
|
|
|
|
|
|
|
|