| 1 | package Number::Phone::StubCountry; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use Number::Phone::Country; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 34 | ▶ | use I18N::LangTags::Detect; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 34 | ▶ | use I18N::LangTags; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 34 | ▶ | use base qw(Number::Phone); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 34 | our $VERSION = '1.5001'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | Number::Phone::StubCountry - Base class for auto-generated country files | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 701 | ▶ | sub country_code { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
country_code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 701 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 701 | return $self->{country_code}; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4299 | ▶ | sub country { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
country: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4299 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4299 | ▶ | if(exists($self->{country})) { return $self->{country}; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2207 | ▶ | if($self->_may_be_noncanonical_number) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 66 | my $digits = $self->format_using('MSISDN'); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 66 | foreach my $translated_prefix (keys %Number::Phone::Country::number_translations) { | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 130 | ▶ | if($digits =~ /^$translated_prefix/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | return $self->{country} = $self->canonical_number->country; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2203 | ref($self)=~ /::(\w+?)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2203 | return $self->{country} = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 24185 | ▶ | sub raw_number { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 24185 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 24185 | $self->{number}; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6212 | ▶ | sub is_valid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6212 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6212 | ▶ | if(exists($self->{is_valid})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 41 | return $self->{is_valid}; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6171 | foreach (map { "is_$_" } qw(specialrate geographic mobile pager tollfree personal ipphone)) { | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 25556 | ▶ | return $self->{is_valid} = 1 if($self->$_()); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1699 | return $self->{is_valid} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 5393 | ▶ | sub is_geographic { shift()->_validator('geographic'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_geographic: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 767 | ▶ | sub is_fixed_line { shift()->_validator('fixed_line'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_fixed_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4707 | ▶ | sub is_mobile { shift()->_validator('mobile'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_mobile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3109 | ▶ | sub is_pager { shift()->_validator('pager'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_pager: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2494 | ▶ | sub is_personal { shift()->_validator('personal_number'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_personal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 7005 | ▶ | sub is_specialrate { shift()->_validator('specialrate'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_specialrate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3525 | ▶ | sub is_tollfree { shift()->_validator('toll_free'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_tollfree: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2387 | ▶ | sub is_ipphone { shift()->_validator('voip'); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ipphone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 29387 | ▶ | sub _validator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validator: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 29387 | my($self, $validator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 29387 | $validator = $self->{validators}->{$validator}; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 29387 | ▶ | return undef unless($validator); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 23885 | ▶ | return $self->raw_number() =~ /^($validator)$/x ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 26 | ▶ | sub areaname { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
areaname: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 26 | my @languages = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 26 | ▶ | if(!@languages) { # nothing specifically asked for? use the locale | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 17 | @languages = I18N::LangTags::implicate_supers(I18N::LangTags::Detect::detect()); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 17 | ▶ | if(!grep { $_ eq 'en' } @languages) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # and fall back to English | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | push @languages, 'en' | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 26 | my $number = $self->raw_number(); | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 26 | LANGUAGE: foreach my $language (@languages) { | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 32 | ▶ | next LANGUAGE unless(exists($self->{areanames}->{$language})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 24 | my %map = %{$self->{areanames}->{$language}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 24 | foreach my $prefix (map { substr($number, 0, $_) } reverse(1..length($number))) { | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 164 | ▶ | return $map{$self->country_code().$prefix} if exists($map{$self->country_code().$prefix}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 220 | ▶ | sub format { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 220 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 220 | my $number = $self->raw_number(); | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 220 | foreach my $formatter (@{$self->{formatters}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1232 | my($leading_digits, $pattern) = map { $formatter->{$_} } qw(leading_digits pattern); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1232 | ▶ | if((!$leading_digits || $number =~ /^($leading_digits)/x) && $number =~ /^$pattern$/x) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
!$leading_digits || $number =~ /^($leading_digits)/x and $number =~ /^$pattern$/x
not $leading_digits or $number =~ /^($leading_digits)/x
MC/DC100%3/3
!$leading_digits || $number =~ /^($leading_digits)/x and $number =~ /^$pattern$/x
not $leading_digits
$number =~ /^($leading_digits)/x
$number =~ /^$pattern$/x
Truth table80%4/5
not(A) or B and C
A= not $leading_digitsB= $number =~ /^($leading_digits)/xC= $number =~ /^$pattern$/x
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 219 | my @bits = $number =~ /^$pattern$/x; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 219 | return join(' ', '+'.$self->country_code(), @bits); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # if there's no formatters defined ... | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | return '+'.$self->country_code().' '.$number; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 20 | ▶ | sub timezones { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timezones: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # If non-geographic use the country-level timezones | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 20 | ▶ | my $number = $self->is_geographic() ? $self->raw_number() : $self->country_code(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | foreach my $i (reverse (0..length($number))) { | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 122 | ▶ | if (my $timezones = $self->{timezones}->{substr($number, 0, $i)}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 19 | my $copy = [sort { $a cmp $b } @$timezones]; # copy the list-ref to avoid manipulation | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 19 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | sub _intra_country_dial_to_leading_0 { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_intra_country_dial_to_leading_0: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | my($from, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | return '0'.$to->raw_number; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | ▶ | sub intra_country_dial_to { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intra_country_dial_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | my($from, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | my $icdt_sub = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | IE => \&_intra_country_dial_to_leading_0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | GB => \&_intra_country_dial_to_leading_0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | JE => \&_intra_country_dial_to_leading_0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | GG => \&_intra_country_dial_to_leading_0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | IM => \&_intra_country_dial_to_leading_0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | }->{$from->country} | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | return $icdt_sub->($from, $to); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return $from->SUPER::intra_country_dial_to(); | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 34 | 1; | |||||||||||||||||||||||||||||||||||||||||||||