| Net-CIDR-MobileJP documentation | Contained in the Net-CIDR-MobileJP distribution. |
Net::CIDR::MobileJP - mobile ip address in Japan
use Net::CIDR::MobileJP;
my $cidr = Net::CIDR::MobileJP->new('net-cidr-mobile-jp.yaml');
$cidr->get_carrier('222.7.56.248');
# => 'E'
Net::CIDR::MobileJP is an utility to detect an ip address is mobile (cellular) ip address or not.
my $cidr = Net::CIDR::MobileJP->new('net-cidr-mobile-jp.yaml'); # from yaml
my $cidr = Net::CIDR::MobileJP->new({E => ['59.135.38.128/25'], ...});
create new instance.
The argument is 'path to yaml' or 'raw data'.
$cidr->get_carrier('222.7.56.248');
Get the career name from IP address.
Carrier name is compatible with HTTP::MobileAgent.
Tokuhiro Matsuno C<< <tokuhiro __at__ mobilefactory.jp> >> Jiro Nishiguchi
Tatsuhiko Miyagawa Masayoshi Sekimura HIROSE, Masaaki
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| Net-CIDR-MobileJP documentation | Contained in the Net-CIDR-MobileJP distribution. |
package Net::CIDR::MobileJP; use strict; use warnings; use 5.00800; use Carp; use Net::CIDR::Lite; use File::ShareDir (); our $VERSION = '0.23'; our $yaml_loader; BEGIN { $yaml_loader = sub { ## no critic if (eval "use YAML::Syck; 1;") { \&YAML::Syck::LoadFile; } else { require YAML; \&YAML::LoadFile; } }->(); }; sub new { my ($class, $stuff) = @_; return bless {spanner => $class->_create_spanner($class->_load_config($stuff))}, $class; } sub _create_spanner { my ($class, $conf) = @_; my $spanner = Net::CIDR::Lite::Span->new; while (my ($carrier, $ip_ranges) = each %$conf) { $spanner->add(do { my $cidr = Net::CIDR::Lite->new; for my $ip_range (@$ip_ranges) { $cidr->add($ip_range); } $cidr; }, $carrier); } return $spanner; } sub _load_config { my ($self, $stuff) = @_; my $data; if (defined $stuff && -f $stuff && -r _) { # load yaml from file $data = $yaml_loader->($stuff); } elsif ($stuff) { # raw data $data = $stuff; } else { # generated file my $file = eval { # use module_file first, this is needed by backward-compatibility File::ShareDir::module_file( 'Net::CIDR::MobileJP', 'cidr.yaml' ) } || eval { File::ShareDir::dist_file( 'Net-CIDR-MobileJP', 'cidr.yaml' ) }; die $@ unless $file; $data = $yaml_loader->($file); } return $data; } sub get_carrier { my ($self, $ip) = @_; my ($carrier,) = map { keys %$_ } values %{$self->{spanner}->find($ip)}; return $carrier || 'N'; } 1; __END__