1 package Number
::Phone
::RO
;
6 use parent qw
/Number::Phone/;
12 our $VERSION = '1.000';
28 return { valid
=> 0 } unless length $nr == 9;
31 $info{geographic
} = $nr =~ /^[23][3-6]/ ?
1 : 0;
32 @info{qw
/fixed_line mobile/} = (1, 0) if $nr =~ /^[23]/;
33 @info{qw
/fixed_line mobile/} = (0, 1) if $nr =~ /^7/;
34 $info{tollfree
} = $nr =~ /^800/ ?
1 : 0;
35 $info{specialrate
} = $nr =~ /^90/ ?
1 : 0;
36 $info{adult
} = 1 if $nr =~ /^906/;
38 my $arealen = $nr =~ /^[23]1/ ?
2 : 3;
39 $info{areacode
} = substr $nr, 0, $arealen;
40 $info{subscriber
} = substr $nr, $arealen;
45 sub _info
{ $cache{${$_[0]}} }
48 my ($class, $nr) = @_;
49 $nr = _normalized
$nr;
50 $cache{$nr} = _analyze_number
$nr;
51 my $self = bless \
$nr, $class;
52 $self->is_valid ?
$self : undef
55 sub is_valid
{ shift->_info->{valid
} }
56 sub is_geographic
{ shift->_info->{geographic
} }
57 sub is_fixed_line
{ shift->_info->{fixed_line
} }
58 sub is_mobile
{ shift->_info->{mobile
} }
59 sub is_tollfree
{ shift->_info->{tollfree
} }
60 sub is_specialrate
{ shift->_info->{specialrate
} }
61 sub is_adult
{ shift->_info->{adult
} }
63 sub country_code
{ 40 }
64 sub regulator
{ 'ANCOM, http://ancom.org.ro'}
66 sub areacode
{ shift->_info->{areacode
} }
67 sub areaname
{ $_[0]->is_geographic ? AREA_NAMES
->{substr $_[0]->areacode, 1} : undef }
68 sub subscriber
{ shift->_info->{subscriber
} }
70 sub format
{ ## no critic (ProhibitBuiltinHomonyms)
75 (substr $self->subscriber, 0, 3),
76 (substr $self->subscriber, 3);
79 sub intra_country_dial_to
{ "0${$_[0]}" }
83 my $ht = HTTP
::Tiny
->new(agent
=> "Number-Phone-RO/$VERSION ");
85 sub query_portabilitate
{
87 $self->_info->{portabilitate_queried
} = 1;
88 my $req = $ht->get("http://portabilitate.ro/ro-no-0$$self");
89 return unless $req->{success
};
90 my ($initial_operator) = $req->{content
} =~ /lnkOperatorInitial">([^<]*)</x;
91 my ($current_operator) = $req->{content
} =~ /lnkOperator">([^<]*)</x;
92 $initial_operator //= $current_operator;
93 $self->_info->{initial_operator
} = $initial_operator;
94 $self->_info->{current_operator
} = $current_operator;
99 $self->query_portabilitate unless $self->_info->{portabilitate_queried
};
100 $self->_info->{initial_operator
}
103 sub operator_ported
{
105 $self->query_portabilitate unless $self->_info->{portabilitate_queried
};
106 $self->_info->{current_operator
}
109 use constant AREA_NAMES
=> {
136 55 => 'Caraș-Severin',
144 63 => 'Bistrița-Năsăud',
160 Number::Phone::RO - Phone number information for Romania (+40)
164 use Number::Phone::RO;
165 my $nr = Number::Phone::RO->new('+40250123456');
166 say $nr->is_geographic; # 1
167 say $nr->is_fixed_line; # 1
168 say $nr->is_mobile; # 0
169 say $nr->is_tollfree; # 0
170 say $nr->is_specialrate; # 0
171 say $nr->areacode; # 250
172 say $nr->areaname; # Vâlcea
173 say $nr->subscriber; # 123456
174 say $nr->operator; # (the name of this number's original operator)
175 say $nr->operator_ported; # (the name of this number's current operator)
176 say $nr->format; # +40 250 123 456
180 See the L<Number::Phone> documentation for usage information. The
181 following methods from L<Number::Phone> are overridden:
185 =item B<is_geographic>
187 =item B<is_fixed_line>
193 =item B<is_specialrate>
197 =item B<country_code>
203 Returns the name and URL of the regulator, ANCOM.
211 =item B<operator_ported>
223 =item B<query_portabilitate>
225 Queries L<http://portabilitate.ro> to get the information for the
226 B<operator> and B<operator_ported> methods. The result is cached.
227 Note that failures (such as number invalid, no internet connection)
228 are also cached. Also note that the service rate limits
229 requests. Going over the (unspecified) rate limit causes the service
230 to ask for a captcha (which is interpreted as a failure by this
233 This method is automatically called by B<operator> and
234 B<operator_ported> the first time they are called. A possible reason
235 for calling it explicitly is refreshing the cache.
241 Only long (10 digits) numbers are supported.
245 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
247 =head1 COPYRIGHT AND LICENSE
249 Copyright (C) 2015-2016 by Marius Gavrilescu
251 This library is free software; you can redistribute it and/or modify
252 it under the same terms as Perl itself, either Perl version 5.20.2 or,
253 at your option, any later version of Perl 5 you may have available.
This page took 0.033525 seconds and 4 git commands to generate.