Net-RIR_CC
view release on metacpan or search on metacpan
package Net::RIR_CC;
use Mouse;
use File::ShareDir qw(dist_file);
use HTML::TableExtract;
use Net::RIR_CC::RIR;
use Carp;
use vars qw($VERSION);
$VERSION = '0.06';
has 'datafile' => ( is => 'ro', isa => 'Str', default => sub {
my $datafile = dist_file( 'Net-RIR_CC', 'list-of-country-codes-and-rirs-ordered-by-country-code.html' );
-f $datafile or die "Missing datafile '$datafile'\n";
return $datafile;
} );
has 'table' => ( is => 'ro', lazy_build => 1 );
has 'cc_map' => ( is => 'ro', isa => 'HashRef', lazy_build => 1 );
has 'a3_map' => ( is => 'ro', isa => 'HashRef', lazy_build => 1 );
sub _build_table {
my $self = shift;
my $te = HTML::TableExtract->new( headers => [ 'A 2', 'A 3', 'Region' ] );
$te->parse_file( $self->datafile );
die sprintf "Found %d tables in datafile, when expecting 1\n", scalar $te->tables
if $te->tables != 1;
return $te->first_table_found;
}
sub _map_table_with_key {
my ($self, $key) = @_;
my $map = {};
for my $row ($self->table->rows) {
my $value = $row->[$#$row];
next if ! defined $value;
$value =~ s/\sNCC$//;
$map->{ $row->[$key] } = $value;
}
return $map;
}
sub _build_cc_map {
my $self = shift;
my $data = $self->_map_table_with_key(0);
# Add missing codes not covered by the NRO page
$data->{RS} = 'RIPE'; # Serbia
$data->{ME} = 'RIPE'; # Montenegro
$data->{JE} = 'RIPE'; # Jersey
$data->{GG} = 'RIPE'; # Guernsey
$data->{IM} = 'RIPE'; # Isle of Man
$data->{MF} = 'ARIN'; # Saint Martin
$data->{SS} = 'AFRINIC'; # South Sudan
$data->{BQ} = 'LACNIC'; # Bonaire, Sint Eustatius and Saba
$data->{UK} = 'RIPE'; # GB is official ISO-3166-2 code
# Region codes
$data->{EU} = 'RIPE'; # Europe
$data->{AP} = 'APNIC'; # Asia-Pacific
return $data;
}
sub _build_a3_map {
my $self = shift;
my $data = $self->_map_table_with_key(1);
# Add missing codes not covered by the NRO page
$data->{SRB} = 'RIPE'; # Serbia
$data->{MNE} = 'RIPE'; # Montenegro
$data->{JEY} = 'RIPE'; # Jersey
( run in 0.565 second using v1.01-cache-2.11-cpan-39bf76dae61 )