blib/lib/Number/Phone/PT.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 94.4% 17 / 18 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 82.3% 70 / 85 CC 18 SCAR 14.5
CC
18
Cov
91%
area_of
5.5
is_mobile
5.0
is_residential
5.0
CRAP 4.3
↑ Summary
1 package Number::Phone::PT;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8  
9 1 our @ISA = qw(Exporter);
10  
11 1 our %EXPORT_TAGS = ( 'all' => [ qw(
12 is_valid is_residential is_mobile is_personal area_of
13 ) ] );
14  
15 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
16  
17 1 our @EXPORT = qw(
18 is_valid is_residential is_mobile is_personal area_of
19 );
20  
21 1 our $VERSION = '0.05';
22  
23 =head1 NAME
24  
25 Number::Phone::PT - Validate Portuguese phone numbers
26  
27 =head1 SYNOPSIS
28  
29 use Number::Phone::PT;
30  
31 $number = 258374162;
32  
33 print "$number is valid" if is_valid($number);
34  
35 print "$number belongs to a home" if is_residential($number);
36  
37 print "$number is a celular phone" if is_mobile($number);
38  
39 print "$number belongs to someone" if is_personal($number);
40 # same thing as ( is_residential($number) or is_mobile($number) )
41  
42 print "$number is from " . area_of($number) if is_residential($number);
43  
44 =cut
45  
46 1 my %indicativos;
47 my %special;
48  
49 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 %indicativos = (
51 21 => 'lisboa',
52 22 => 'porto',
53 231 => 'mealhada',
54 232 => 'viseu',
55 233 => 'figueira da foz',
56 234 => 'aveiro',
57 235 => 'arganil',
58 236 => 'pombal',
59 238 => 'seia',
60 239 => 'coimbra',
61 241 => 'abrantes',
62 242 => 'ponte de sôr',
63 243 => 'santarém',
64 244 => 'leiria',
65 245 => 'portalegre',
66 249 => 'torres novas',
67 251 => 'valença',
68 252 => 'vila nova de famalicão',
69 253 => 'braga',
70 254 => 'peso da régua',
71 255 => 'penafiel',
72 256 => 'são joão da madeira',
73 258 => 'viana do castelo',
74 259 => 'vila real',
75 261 => 'torres vedras',
76 262 => 'caldas da raínha',
77 263 => 'vila franca de xira',
78 265 => 'setúbal',
79 266 => 'évora',
80 268 => 'estremoz',
81 269 => 'santiago do cacém',
82 271 => 'guarda',
83 272 => 'castelo branco',
84 273 => 'bragança',
85 274 => 'proença-a-nova',
86 275 => 'covilhã',
87 276 => 'chaves',
88 277 => 'idanha-a-nova',
89 278 => 'mirandela',
90 279 => 'moncorvo',
91 281 => 'tavira',
92 282 => 'portimão',
93 283 => 'odemira',
94 284 => 'beja',
95 285 => 'moura',
96 286 => 'castro verde',
97 289 => 'faro',
98 291 => 'funchal, porto santo',
99 292 => 'corvo, faial, flores, horta, pico',
100 295 => 'angra do heroísmo, graciosa, são jorge, terceira',
101 296 => 'ponta delgada, são miguel, santa maria',
102  
103 91 => 'rede móvel 91 (Vodafone / Yorn)',
104 93 => 'rede móvel 93 (Optimus)',
105 96 => 'rede móvel 96 (TMN)',
106  
107 707 => 'número único',
108 760 => 'número único',
109 800 => 'número grátis',
110 808 => 'chamada local',
111 );
112  
113 1 %special = ( # currently unused (yet)
114 # Telefones úteis
115 120 => 'Chamadas Nacionais a Pagar no Destino',
116 120 => 'PT Multivozes',
117 16200 => 'Serviço a Clientes',
118 12161 => 'Despertar',
119 1583 => 'Telegramas Nacional',
120 16208 => 'Assistência Técnica',
121 # Serviços de informações
122 118 => 'Serviço Informativo Nacional',
123 12150 => 'Meteorologia',
124 12151 => 'Horas',
125 12153 => 'Notícias',
126 12157 => 'Desporto',
127 12158 => 'Lotaria, Totobola e Totoloto',
128 # Internacional
129 171 => 'Chamadas com Assistência',
130 177 => 'Listas Telefónicas Internacionais',
131 179 => 'Informações Gerais sobre o Serviço Telefónico Internacional',
132 1582 => 'Telegramas Internacional',
133 );
134 }
135  
136 208 ▶sub is_valid {
Subroutine is_valid: called CC=5 SCAR=16.1
Pod undocumented
137 208 ▶ $_ = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
2080
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
138 208 ▶ unless (/^\d{9}$/) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\d{9}$/) 4 204 208
139  
140 204 for my $ind (keys %indicativos) {
141 7207 ▶ /^$ind/ && return 1;
Branch: 1 branch
BranchTrueFalseTotal
/^$ind/ and return 1 203 7004 7207
142 }
143  
144 1 return 0
145 }
146  
147 4 ▶sub is_personal {
Subroutine is_personal: called CC=2 SCAR=6.9
Pod undocumented
148 4 ▶ is_mobile(@_) or is_residential(@_);
Branch: 1 branch
BranchTrueFalseTotal
is_mobile(@_) or is_residential(@_) 1 3 4
149 }
150  
151 8 ▶sub is_mobile {
Subroutine is_mobile: called CC=5 SCAR=16.1
Pod undocumented
152 8 ▶ is_valid(@_) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
is_valid(@_) or return 0 7 1 8
153 7 ▶ $_ = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
70
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
154 7 for my $ind (grep /^9/, keys %indicativos) {
155 19 ▶ /^$ind/ && return 1;
Branch: 1 branch
BranchTrueFalseTotal
/^$ind/ and return 1 3 16 19
156 }
157 4 return 0
158 }
159  
160 7 ▶sub is_residential {
Subroutine is_residential: called CC=5 SCAR=16.1
Pod undocumented
161 7 ▶ is_valid(@_) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
is_valid(@_) or return 0 6 1 7
162 6 ▶ $_ = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
60
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
163 6 for my $ind (grep /^2/, keys %indicativos) {
164 172 ▶ /^$ind/ && return 1;
Branch: 1 branch
BranchTrueFalseTotal
/^$ind/ and return 1 3 169 172
165 }
166 3 return 0
167 }
168  
169 2 ▶sub area_of {
Subroutine area_of: called CC=5 SCAR=17.1
Pod undocumented
170 2 ▶ is_valid(@_) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
is_valid(@_) or return 0 2 0 2
171 2 ▶ $_ = shift || return 0;
Condition50%1/2
shift() || (return 0)
l!l
20
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
172 2 for my $ind (grep /^2/, keys %indicativos) {
173 38 ▶ /^$ind/ && return $indicativos{$ind};
Branch: 1 branch
BranchTrueFalseTotal
/^$ind/ and return $indicativos{$ind} 2 36 38
174 }
175 0 return 0;
176 }
177  
178 1 1;
179 __END__
↑ Summary