X-Git-Url: http://git.ieval.ro/?p=number-phone-ro.git;a=blobdiff_plain;f=lib%2FNumber%2FPhone%2FRO.pm;h=adf4e2d19a7952dc4fa56e82ec18ff99199a4ba5;hp=d2d94d5f4d4d37ed975d1ca8fe6c14bd5bf94bb8;hb=910b926d93ef91e4c40d4c4c7b7ac071540bfdd7;hpb=5f6a17efd828bb731bfd69bfd694d983e428e500 diff --git a/lib/Number/Phone/RO.pm b/lib/Number/Phone/RO.pm index d2d94d5..adf4e2d 100644 --- a/lib/Number/Phone/RO.pm +++ b/lib/Number/Phone/RO.pm @@ -9,7 +9,7 @@ use re '/s'; sub AREA_NAMES (); ## no critic (ProhibitSubroutinePrototypes) -our $VERSION = '0.001'; +our $VERSION = '0.002'; our %cache; @@ -78,6 +78,34 @@ sub format { ## no critic (ProhibitBuiltinHomonyms) sub intra_country_dial_to { "0${$_[0]}" } +use HTTP::Tiny; + +my $ht = HTTP::Tiny->new(agent => "Number-Phone-RO/$VERSION "); + +sub query_portabilitate { + my ($self) = @_; + $self->_info->{portabilitate_queried} = 1; + my $req = $ht->get("http://portabilitate.ro/ro-no-0$$self"); + return unless $req->{success}; + my ($initial_operator) = $req->{content} =~ /lnkOperatorInitial">([^<]*){content} =~ /lnkOperator">([^<]*)_info->{initial_operator} = $initial_operator; + $self->_info->{current_operator} = $current_operator; +} + +sub operator { + my ($self) = @_; + $self->query_portabilitate unless $self->_info->{portabilitate_queried}; + $self->_info->{initial_operator} +} + +sub operator_ported { + my ($self) = @_; + $self->query_portabilitate unless $self->_info->{portabilitate_queried}; + $self->_info->{current_operator} +} + use constant AREA_NAMES => { 1 => 'București', 30 => 'Suceava', @@ -135,20 +163,20 @@ Number::Phone::RO - Phone number information for Romania (+40) use Number::Phone::RO; my $nr = Number::Phone::RO->new('+40250123456'); - say $nr->is_geographic; # 1 - say $nr->is_fixed_line; # 1 - say $nr->is_mobile; # 0 - say $nr->is_tollfree; # 0 - say $nr->is_specialrate; # 0 - say $nr->areacode; # 250 - say $nr->areaname; # Vâlcea - say $nr->subscriber; # 123456 - say $nr->format; # +40 250 123 456 + say $nr->is_geographic; # 1 + say $nr->is_fixed_line; # 1 + say $nr->is_mobile; # 0 + say $nr->is_tollfree; # 0 + say $nr->is_specialrate; # 0 + say $nr->areacode; # 250 + say $nr->areaname; # Vâlcea + say $nr->subscriber; # 123456 + say $nr->operator; # (the name of this number's original operator) + say $nr->operator_ported; # (the name of this number's current operator) + say $nr->format; # +40 250 123 456 =head1 DESCRIPTION -This module is a work in progress. See the L section below. - See the L documentation for usage information. The following methods from L are overridden: @@ -176,18 +204,40 @@ Returns the name and URL of the regulator, ANCOM. =item B +=item B + +=item B + =item B =item B =back +Other methods: + +=over 4 + +=item B + +Queries L to get the information for the +B and B methods. The result is cached. +Note that failures (such as number invalid, no internet connection) +are also cached. Also note that the service rate limits +requests. Going over the (unspecified) rate limit causes the service +to ask for a captcha (which is interpreted as a failure by this +function). + +This method is automatically called by B and +B the first time they are called. A possible reason +for calling it explicitly is refreshing the cache. + +=back + =head1 TODO Only long (10 digits) numbers are supported. -Should query L to implement B and B. - =head1 AUTHOR Marius Gavrilescu, Emarius@ieval.roE