| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Number::Phone::PT; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22166
|
use 5.006; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
586
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
12
|
|
|
|
|
|
|
is_valid is_residential is_mobile is_personal area_of |
|
13
|
|
|
|
|
|
|
) ] ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
18
|
|
|
|
|
|
|
is_valid is_residential is_mobile is_personal area_of |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my %indicativos; |
|
47
|
|
|
|
|
|
|
my %special; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
BEGIN { |
|
50
|
1
|
|
|
1
|
|
66
|
%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
|
|
|
|
|
578
|
%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
|
|
|
|
|
|
|
sub is_valid { |
|
137
|
208
|
|
50
|
208
|
0
|
804
|
$_ = shift || return 0; |
|
138
|
208
|
100
|
|
|
|
887
|
unless (/^\d{9}$/) { return 0 } |
|
|
4
|
|
|
|
|
24
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
204
|
|
|
|
|
1678
|
for my $ind (keys %indicativos) { |
|
141
|
7484
|
100
|
|
|
|
75190
|
/^$ind/ && return 1; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
1
|
|
|
|
|
9
|
return 0 |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub is_personal { |
|
148
|
4
|
100
|
|
4
|
0
|
11
|
is_mobile(@_) or is_residential(@_); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub is_mobile { |
|
152
|
8
|
100
|
|
8
|
0
|
18
|
is_valid(@_) || return 0; |
|
153
|
7
|
|
50
|
|
|
44
|
$_ = shift || return 0; |
|
154
|
7
|
|
|
|
|
132
|
for my $ind (grep /^9/, keys %indicativos) { |
|
155
|
20
|
100
|
|
|
|
201
|
/^$ind/ && return 1; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
4
|
|
|
|
|
30
|
return 0 |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub is_residential { |
|
161
|
7
|
100
|
|
7
|
0
|
17
|
is_valid(@_) || return 0; |
|
162
|
6
|
|
50
|
|
|
37
|
$_ = shift || return 0; |
|
163
|
6
|
|
|
|
|
195
|
for my $ind (grep /^2/, keys %indicativos) { |
|
164
|
197
|
100
|
|
|
|
1742
|
/^$ind/ && return 1; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
3
|
|
|
|
|
24
|
return 0 |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub area_of { |
|
170
|
2
|
50
|
|
2
|
0
|
8
|
is_valid(@_) || return 0; |
|
171
|
2
|
|
50
|
|
|
14
|
$_ = shift || return 0; |
|
172
|
2
|
|
|
|
|
70
|
for my $ind (grep /^2/, keys %indicativos) { |
|
173
|
16
|
100
|
|
|
|
181
|
/^$ind/ && return $indicativos{$ind}; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
0
|
|
|
|
|
|
return 0; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |
|
179
|
|
|
|
|
|
|
__END__ |