line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Phone::Normalize; |
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
698197
|
use strict; |
|
19
|
|
|
|
|
55
|
|
|
19
|
|
|
|
|
1018
|
|
4
|
19
|
|
|
19
|
|
166
|
use warnings; |
|
19
|
|
|
|
|
34
|
|
|
19
|
|
|
|
|
575
|
|
5
|
|
|
|
|
|
|
|
6
|
19
|
|
|
19
|
|
106
|
use Carp; |
|
19
|
|
|
|
|
40
|
|
|
19
|
|
|
|
|
2173
|
|
7
|
19
|
|
|
19
|
|
108
|
use Exporter; |
|
19
|
|
|
|
|
144
|
|
|
19
|
|
|
|
|
99350
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT = qw(phone_intl phone_local); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.220'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _kill_vanity { |
15
|
751
|
|
|
751
|
|
1155
|
my $number = shift; |
16
|
751
|
|
|
|
|
1387
|
$number =~ s/[abc]/2/gi; |
17
|
751
|
|
|
|
|
1012
|
$number =~ s/[def]/3/gi; |
18
|
751
|
|
|
|
|
972
|
$number =~ s/[ghi]/4/gi; |
19
|
751
|
|
|
|
|
1060
|
$number =~ s/[jkl]/5/gi; |
20
|
751
|
|
|
|
|
963
|
$number =~ s/[mno]/6/gi; |
21
|
751
|
|
|
|
|
997
|
$number =~ s/[pqrs]/7/gi; |
22
|
751
|
|
|
|
|
3800
|
$number =~ s/[tuv]/8/gi; |
23
|
751
|
|
|
|
|
1068
|
$number =~ s/[wxyz]/9/gi; |
24
|
751
|
|
|
|
|
1422
|
return $number; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _remove_prefix { |
28
|
271
|
|
|
271
|
|
531
|
my ($number,$prefix) = @_; |
29
|
271
|
|
|
|
|
1630
|
$number = _kill_vanity($number); $number =~ s/[^0-9]//g; |
|
271
|
|
|
|
|
868
|
|
30
|
271
|
|
|
|
|
2156
|
$prefix = _kill_vanity($prefix); $prefix =~ s/[^0-9]//g; |
|
271
|
|
|
|
|
8695
|
|
31
|
|
|
|
|
|
|
|
32
|
271
|
100
|
|
|
|
7680
|
if ($number =~ m/^$prefix/) { |
33
|
120
|
|
|
|
|
5057
|
for(my $i=0;$i
|
34
|
229
|
|
|
|
|
989
|
$_[0] =~ s/^[^0-9A-Z]*[0-9A-Z][^0-9A-Z]*//i; |
35
|
|
|
|
|
|
|
} |
36
|
120
|
|
|
|
|
1174
|
return $_[0]; |
37
|
|
|
|
|
|
|
} else { |
38
|
151
|
|
|
|
|
1823
|
return undef; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
43
|
99
|
|
|
99
|
1
|
333
|
my($class,%param) = @_; |
44
|
99
|
|
33
|
|
|
731
|
my $self = bless {}, ref($class) || $class; |
45
|
|
|
|
|
|
|
|
46
|
99
|
50
|
|
|
|
316
|
%{$self} = %{$class} if (ref $class); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
|
48
|
99
|
|
|
|
|
291
|
foreach(keys %param) |
49
|
|
|
|
|
|
|
{ |
50
|
232
|
50
|
|
|
|
1015
|
if(my $accessor = $self->can($_)) |
51
|
|
|
|
|
|
|
{ |
52
|
232
|
|
|
|
|
540
|
&$accessor($self,$param{$_}) |
53
|
|
|
|
|
|
|
}else{ |
54
|
0
|
|
|
|
|
0
|
croak "Invalid parameter: $_"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
99
|
|
|
|
|
376
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _self { |
62
|
229
|
|
|
229
|
|
493
|
my($self,%param) = @_; |
63
|
|
|
|
|
|
|
|
64
|
229
|
100
|
|
|
|
826
|
return new(__PACKAGE__,%param) unless ref($self); |
65
|
136
|
50
|
|
|
|
331
|
return $self->new(%param) if %param; |
66
|
136
|
|
|
|
|
377
|
return $self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub intl { |
70
|
95
|
|
|
95
|
1
|
250
|
my ($self,$number,%param) = @_; |
71
|
95
|
|
|
|
|
237
|
$self = _self($self,%param); |
72
|
|
|
|
|
|
|
|
73
|
95
|
|
|
|
|
263
|
my $has_prefix = ($number =~ m/^[^A-Z0-9]*\+/i); |
74
|
|
|
|
|
|
|
|
75
|
95
|
100
|
|
|
|
234
|
$number = _kill_vanity $number unless $self->VanityOK; |
76
|
|
|
|
|
|
|
|
77
|
95
|
|
|
|
|
376
|
$number =~ s/[^0-9A-Z]+/ /gi; # Normalize Punctuation |
78
|
95
|
|
|
|
|
1171
|
$number =~ s/^ *(.*?) *$/$1/; # Remove leading/trailing Whitespace |
79
|
|
|
|
|
|
|
|
80
|
95
|
100
|
|
|
|
360
|
return '+'.$number if $has_prefix; # Number was alreads in int'l format |
81
|
84
|
50
|
|
|
|
736
|
return undef unless $number; # no significant digits |
82
|
|
|
|
|
|
|
|
83
|
84
|
|
|
|
|
181
|
my $nn; |
84
|
|
|
|
|
|
|
|
85
|
84
|
100
|
100
|
|
|
250
|
if($nn = _remove_prefix($number,$self->IntlPrefix)) { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
86
|
6
|
|
|
|
|
49
|
return '+'.$nn; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif(($nn = _remove_prefix($number,$self->LDPrefix)) && defined $self->CountryCode) { |
89
|
29
|
|
|
|
|
81
|
return '+'.($self->CountryCode).' '.$nn; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif(defined $self->CountryCode && defined $self->AreaCode) { |
92
|
23
|
|
|
|
|
70
|
return '+'.($self->CountryCode).' '.($self->AreaCode).' '.$number; |
93
|
|
|
|
|
|
|
} |
94
|
26
|
|
|
|
|
105
|
return undef; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub local { |
98
|
134
|
|
|
134
|
1
|
435
|
my ($self,$number,%param) = @_; |
99
|
134
|
|
|
|
|
435
|
$self = _self($self,%param); |
100
|
|
|
|
|
|
|
|
101
|
134
|
|
|
|
|
506
|
my $has_prefix = ($number =~ m/^[^A-Z0-9 ]*\+/i); |
102
|
|
|
|
|
|
|
|
103
|
134
|
100
|
|
|
|
323
|
$number = _kill_vanity $number unless $self->VanityOK; |
104
|
134
|
|
|
|
|
11277
|
$number =~ s/[^0-9A-Z]+/ /gi; # Normalize Punctuation |
105
|
134
|
|
|
|
|
1083
|
$number =~ s/^ *(.*?) *$/$1/; # Remove leading/trailing Whitespace |
106
|
|
|
|
|
|
|
|
107
|
134
|
50
|
|
|
|
367
|
return undef unless $number ne ''; # no significant digits |
108
|
|
|
|
|
|
|
|
109
|
134
|
|
|
|
|
176
|
my $nn; |
110
|
|
|
|
|
|
|
|
111
|
134
|
100
|
|
|
|
287
|
if($has_prefix) { |
112
|
|
|
|
|
|
|
# |
113
|
|
|
|
|
|
|
# Number is in international format |
114
|
|
|
|
|
|
|
# |
115
|
68
|
100
|
100
|
|
|
211
|
if(defined $self->CountryCodeOut && defined $self->AreaCodeOut && (!$self->AlwaysLD) |
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
116
|
|
|
|
|
|
|
&& ($nn = _remove_prefix($number,($self->CountryCodeOut).($self->AreaCodeOut)))) { |
117
|
21
|
|
|
|
|
154
|
return $nn; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif($self->CountryCodeOut |
120
|
|
|
|
|
|
|
&& ($nn = _remove_prefix($number,$self->CountryCodeOut))) { |
121
|
32
|
|
|
|
|
88
|
return ($self->LDPrefixOut).$nn; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else { |
124
|
15
|
|
|
|
|
58
|
return ($self->IntlPrefixOut).$number |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} else { |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
# Number is in local format |
129
|
|
|
|
|
|
|
|
130
|
66
|
|
|
|
|
255
|
@_ = ($self, $self->intl($number)); |
131
|
66
|
100
|
|
|
|
319
|
goto &local unless !defined $_[1]; |
132
|
|
|
|
|
|
|
|
133
|
26
|
100
|
100
|
|
|
58
|
if(defined $self->AreaCodeOut && (!$self->AlwaysLD) |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
134
|
|
|
|
|
|
|
&& ($nn = _remove_prefix($number,($self->LDPrefix).($self->AreaCodeOut)))) { |
135
|
4
|
|
|
|
|
26
|
return $nn; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
elsif(($nn = _remove_prefix($number,($self->LDPrefix)))) { |
138
|
12
|
|
|
|
|
36
|
return ($self->LDPrefixOut).$nn; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif(defined $self->AreaCode && defined $self->AreaCodeOut |
141
|
|
|
|
|
|
|
&& $self->AreaCode ne $self->AreaCodeOut) { |
142
|
1
|
|
|
|
|
4
|
return ($self->LDPrefixOut).($self->AreaCode).' '.$number |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
elsif($self->AlwaysLD && defined $self->AreaCodeOut) |
145
|
|
|
|
|
|
|
{ |
146
|
2
|
|
|
|
|
8
|
return ($self->LDPrefixOut).($self->AreaCodeOut).' '.$number |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else |
149
|
|
|
|
|
|
|
{ |
150
|
7
|
|
|
|
|
62
|
return $number; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub IntlPrefix { |
156
|
107
|
|
|
107
|
1
|
677
|
my $self = shift; |
157
|
107
|
50
|
|
|
|
11063
|
my $old_value = defined $self->{'IntlPrefix'} ? $self->{'IntlPrefix'} : '00'; |
158
|
107
|
50
|
|
|
|
349
|
$self->{'IntlPrefix'} = shift if @_; |
159
|
107
|
|
|
|
|
308
|
return $old_value; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub LDPrefix { |
163
|
159
|
|
|
159
|
1
|
743
|
my $self = shift; |
164
|
159
|
50
|
|
|
|
407
|
my $old_value = defined $self->{'LDPrefix'} ? $self->{'LDPrefix'} : '0'; |
165
|
159
|
50
|
|
|
|
348
|
$self->{'LDPrefix'} = shift if @_; |
166
|
159
|
|
|
|
|
392
|
return $old_value; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub IntlPrefixOut { |
170
|
23
|
|
|
23
|
1
|
36
|
my $self = shift; |
171
|
23
|
50
|
|
|
|
91
|
my $old_value = defined $self->{'IntlPrefixOut'} ? $self->{'IntlPrefixOut'} : $self->IntlPrefix; |
172
|
23
|
100
|
|
|
|
83
|
$self->{'IntlPrefixOut'} = shift if @_; |
173
|
23
|
|
|
|
|
174
|
return $old_value; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub LDPrefixOut { |
177
|
47
|
|
|
47
|
1
|
75
|
my $self = shift; |
178
|
47
|
50
|
|
|
|
155
|
my $old_value = defined $self->{'LDPrefixOut'} ? $self->{'LDPrefixOut'} : $self->LDPrefix; |
179
|
47
|
50
|
|
|
|
117
|
$self->{'LDPrefixOut'} = shift if @_; |
180
|
47
|
|
|
|
|
503
|
return $old_value; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub CountryCode { |
184
|
397
|
|
|
397
|
1
|
1182
|
my $self = shift; |
185
|
397
|
|
|
|
|
798
|
my $old_value = $self->{'CountryCode'}; |
186
|
397
|
100
|
|
|
|
893
|
$self->{'CountryCode'} = shift if @_; |
187
|
397
|
|
|
|
|
1298
|
return $old_value; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub AreaCode { |
191
|
314
|
|
|
314
|
1
|
387
|
my $self = shift; |
192
|
314
|
|
|
|
|
12568
|
my $old_value = $self->{'AreaCode'}; |
193
|
314
|
100
|
|
|
|
756
|
$self->{'AreaCode'} = shift if @_; |
194
|
314
|
|
|
|
|
925
|
return $old_value; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub CountryCodeOut { |
198
|
197
|
|
|
197
|
1
|
243
|
my $self = shift; |
199
|
197
|
100
|
|
|
|
541
|
my $old_value = defined $self->{'CountryCodeOut'} ? $self->{'CountryCodeOut'} : $self->CountryCode; |
200
|
197
|
100
|
|
|
|
868
|
$self->{'CountryCodeOut'} = shift if @_; |
201
|
197
|
|
|
|
|
1356
|
return $old_value; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub AreaCodeOut { |
205
|
204
|
|
|
204
|
1
|
293
|
my $self = shift; |
206
|
204
|
100
|
|
|
|
557
|
my $old_value = $self->{'AreaCodeOut'} ? $self->{'AreaCodeOut'} : $self->AreaCode; |
207
|
204
|
100
|
|
|
|
759
|
$self->{'AreaCodeOut'} = shift if @_; |
208
|
204
|
|
|
|
|
1535
|
return $old_value; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub VanityOK { |
212
|
247
|
|
|
247
|
1
|
336
|
my $self = shift; |
213
|
247
|
|
|
|
|
389
|
my $old_value = $self->{'VanityOK'}; |
214
|
247
|
100
|
|
|
|
564
|
$self->{'VanityOK'} = shift if @_; |
215
|
247
|
|
|
|
|
814
|
return $old_value; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub AlwaysLD { |
219
|
109
|
|
|
109
|
1
|
134
|
my $self = shift; |
220
|
109
|
|
66
|
|
|
354
|
my $old_value = $self->{'AlwaysLD'} && defined $self->AreaCodeOut; |
221
|
109
|
100
|
|
|
|
835
|
$self->{'AlwaysLD'} = shift if @_; |
222
|
109
|
|
|
|
|
1154
|
return $old_value; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
22
|
|
|
22
|
1
|
127
|
sub phone_intl { unshift @_, undef; goto &intl; } |
|
22
|
|
|
|
|
79
|
|
226
|
71
|
|
|
71
|
1
|
305
|
sub phone_local { unshift @_, undef; goto &local; } |
|
71
|
|
|
|
|
247
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
1; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
__END__ |