FR.pm

filter: Statementstmt 80.6% 108 / 134 Branchbran 53.8% 28 / 52 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 57.7% 26 / 45 Podpod 100% 23 / 23 totaltotal 71.2% 188 / 264 CC 29 SCAR 13.4
CC
29
Cov
72%
import
10.9
new
6.3
is_tollfree
6.0
CRAP 3.8
↑ Summary FR/Full.pm »
1 12 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Number::Phone::FR;
6  
7 # $VERSION is limited to 2 digits after the dot
8 # Other digits are reserved for ARCEP data versonning
9 # in Number::Phone::FR::Full
10 12 our $VERSION = '0.09';
11  
12 12 ▶use Number::Phone;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶use parent 'Number::Phone';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 12 my %pkg2impl;
19  
20 # Select the implementation to use via "use Number::Phone::FR"
21  
22 sub import
23 68 ▶{
Subroutine import: called CC=8 SCAR=23.9
24 68 my $class = shift;
25 68 ▶ croak "invalid sub-class" unless $class->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 68 68
26 68 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) { } 68 0 68
27 68 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 60 68
28 8 $class = $_[0];
29 8 $class =~ s/^:?(.)/\U$1/;
30 8 substr($class, 0, 0) = __PACKAGE__.'::';
31  
32 8 my $level = 0;
33 8 my $pkg;
34 8 ▶ while (($pkg = (caller $level)[0]) =~ /^Number::Phone(?:::|$)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (($pkg = (caller $level)[0]) =~ /^Number::Phone(?:::|$)/) 0 8 8
35 0 $level++;
36 }
37 8 $pkg2impl{$pkg} = $class;
38  
39 # Load the class
40 8 ▶ eval "require $class; 1" or croak "$@\n";
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class; 1" or croak("$@\n") 8 0 8
41 8 ▶ $class->isa(__PACKAGE__) or croak "$class is not a valid class";
Branch: 1 branch
BranchTrueFalseTotal
$class->isa(__PACKAGE__) or croak("$class is not a valid class") 8 0 8
42 }
43 } else {
44 #croak "unexpected arguments for import" if @_;
45 0 my $pkg = (caller)[0];
46 0 ▶ croak "$class is private" unless $pkg =~ m/^Number::Phone(?:::|$)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ /^Number::Phone(?:::|$)/ 0 0 0
47 0 $pkg2impl{$pkg} = $class;
48 }
49 }
50  
51 #END {
52 # foreach (sort keys %pkg2impl) {
53 # print STDERR "# $_ => $pkg2impl{$_}\n";
54 # }
55 #}
56  
57  
58 # Select the implementation based on $pkg2impl
59 sub _get_class
60 744 ▶{
Subroutine _get_class: called CC=5 SCAR=16.2
61 744 my ($class) = @_;
62 744 ▶ return $class if defined $class && $class ne __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if defined $class and $class ne __PACKAGE__ 0 744 744
Condition66%2/3
defined $class and $class ne __PACKAGE__
!ll&&!rl&&r
5132310
MC/DC0%0/2
defined $class and $class ne __PACKAGE__
defined $class $class ne __PACKAGE__
Truth table66%2/3
A and B
A= defined $classB= $class ne __PACKAGE__
ABresult
0X0
100
111
63 744 my $level = 0;
64 744 my ($pkg, $impl);
65 744 ▶ while ($pkg = (caller $level)[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg = (caller $level)[0]) 2142 250 2392
66 2142 $impl = $pkg2impl{$pkg};
67 2142 ▶ return $impl if defined $impl;
Branch: 1 branch
BranchTrueFalseTotal
if defined $impl 494 1648 2142
68 1648 $level++;
69 }
70 # Default implementation
71 250 return __PACKAGE__;
72 }
73  
74  
75 12 ▶use constant RE_SUBSCRIBER =>
Subroutine BEGIN: called CC=1 SCAR=0.0
76 qr{
77 \A
78 (?:
79 \+33 # Préfixe international (+33 numéro)
80 | (?:3651)?
81 (?:
82 [04789] # Transporteur par défaut (0) ou Sélection du transporteur
83 | 16 [0-9]{2} # Sélection du transporteur
84 ) (?:033)? # Préfixe international (0033 numéro)
85 ) ([1-9][0-9]{8}) # Numéro de ligne
86 \z
87 12 }xs;
88  
89 12 ▶use constant RE_FULL =>
Subroutine BEGIN: called CC=1 SCAR=0.0
90 qr{
91 \A (?:
92 1 (?:
93 0[0-9]{2} # Opérateur
94 | 5 # SAMU
95 | 7 # Police/gendarmerie
96 | 8 # Pompiers
97 | 1 (?:
98 2 # Numéro d'urgence européen
99 | 5 # Urgences sociales
100 | 6000 # 116000 : Enfance maltraitée
101 | 8[0-9]{3} # 118XYZ : Renseignements téléphoniques
102 | 9 # Enfance maltraitée
103 )
104 )
105 | 3[0-9]{3}
106 | (?:
107 \+33 # Préfixe international (+33 numéro)
108 | (?:3651)? # Préfixe d'anonymisation
109 (?:
110 [04789] # Transporteur par défaut (0) ou Sélection du transporteur
111 | 16 [0-9]{2} # Sélection du transporteur
112 ) (?:033)? # Préfixe international (0033 numéro)
113 ) [1-9][0-9]{8} # Numéro de ligne
114 ) \z
115 12 }xs;
116  
117  
118  
119  
120 sub country_code() { 33 }
121  
122 # Number::Phone's implementation of country() does not yet allow
123 # clean subclassing so we explicitely implement it here
124 sub country() { 'FR' }
125  
126  
127 sub new
128 231 ▶{
Subroutine new: called CC=6 SCAR=18.4
Pod documented
129 231 my $class = shift;
130 231 my $number = shift;
131 231 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 231 231
132  
133 231 $class = _get_class($class);
134  
135 231 ▶ croak "No number given to ".__PACKAGE__."->new()\n" unless defined $number;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 231 231
136 231 ▶ croak "Invalid phone number (scalar expected)" if ref $number;
Branch: 1 branch
BranchTrueFalseTotal
if ref $number 0 231 231
137  
138 231 my $num = $number;
139 231 $num =~ s/[^+0-9]//g;
140 231 ▶ return Number::Phone->new("+$1") if $num =~ /\A(?:\+|00)((?:[^3]|3[^3]).*)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $num =~ /\A(?:\+|00)((?:[^3]|3[^3]).*)\z/ 0 231 231
141  
142 231 ▶ return is_valid($number) ? bless(\$num, $class) : undef;
Branch: 1 branch
BranchTrueFalseTotal
is_valid($number) ? : 171 60 231
143 }
144  
145  
146 sub is_valid
147 324 ▶{
Subroutine is_valid: called CC=3 SCAR=12.0
Pod documented
148 324 my ($number) = (@_);
149 324 ▶ return 1 if blessed($number) && $number->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($number) and $number->isa(__PACKAGE__) 0 324 324
Condition33%1/3
builtin::blessed($number) and $number->isa(__PACKAGE__)
!ll&&!rl&&r
32400
MC/DC0%0/2
builtin::blessed($number) and $number->isa(__PACKAGE__)
builtin::blessed($number) $number->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($number)B= $number->isa(__PACKAGE__)
ABresult
0X0
100
111
150  
151 324 my $class = _get_class();
152 324 return $number =~ $class->RE_FULL;
153 }
154  
155  
156 sub is_allocated
157 0 ▶{
Subroutine is_allocated: not called CC=1 SCAR=6.9
Pod documented
158 undef
159 0 }
160  
161 sub is_in_use
162 0 ▶{
Subroutine is_in_use: not called CC=1 SCAR=6.9
Pod documented
163 undef
164 0 }
165  
166 sub _num(\@)
167 392 ▶{
Subroutine _num: called CC=2 SCAR=6.9
168 392 my $args = shift;
169 392 my $num = shift @$args;
170 392 my $class = ref $num;
171 392 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) { } 203 189 392
172 203 $num = ${$num};
173 } else {
174 189 $class = _get_class();
175 189 $num = shift @$args;
176 }
177 392 return ($class, $num);
178 }
179  
180 # Vérifie les chiffres du numéro de ligne
181 # Les numéros spéciaux ne matchent pas
182 sub _check_line
183 180 ▶{
Subroutine _check_line: called CC=3 SCAR=11.0
184 180 my ($class, $num) = _num(@_);
185 180 my @matches = ($num =~ $class->RE_SUBSCRIBER);
186 180 ▶ return 0 unless @matches;
Branch: 1 branch
BranchTrueFalseTotal
unless @matches 0 180 180
187 180 my $line = (grep { defined } @matches)[0];
188 180 ▶ return 1 if $line =~ shift;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ (shift()) 90 90 180
189 undef
190 90 }
191  
192 sub is_geographic
193 60 ▶{
Subroutine is_geographic: called CC=1 SCAR=0.0
Pod documented
194 60 return _check_line(@_, qr/\A[1-5].{8}\z/)
195 }
196  
197 sub is_fixed_line
198 60 ▶{
Subroutine is_fixed_line: called CC=1 SCAR=0.0
Pod documented
199 60 return _check_line(@_, qr/\A[1-5].{8}\z/)
200 }
201  
202 sub is_mobile
203 60 ▶{
Subroutine is_mobile: called CC=1 SCAR=0.0
Pod documented
204 60 return _check_line(@_, qr/\A[67].{8}\z/)
205 }
206  
207 sub is_pager
208 0 ▶{
Subroutine is_pager: not called CC=1 SCAR=6.9
Pod documented
209 undef
210 0 }
211  
212 sub is_ipphone
213 0 ▶{
Subroutine is_ipphone: not called CC=1 SCAR=6.9
Pod documented
214 0 return _check_line(@_, qr/\A9/)
215 }
216  
217 sub is_isdn
218 0 ▶{
Subroutine is_isdn: not called CC=1 SCAR=6.9
Pod documented
219 undef
220 0 }
221  
222 sub is_tollfree
223 0 ▶{
Subroutine is_tollfree: not called CC=2 SCAR=17.9
Pod documented
224 #return 1
225 # FIXME Gérer les préfixes
226 0 ▶ return 0 unless $_[1] =~ /\A08[0-9]{8}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ /\A08[0-9]{8}\z/ 0 0 0
227 undef
228 0 }
229  
230 sub is_specialrate
231 0 ▶{
Subroutine is_specialrate: not called CC=2 SCAR=17.9
Pod documented
232 # FIXME Gérer les préfixes
233 0 ▶ return 0 unless $_[1] =~ /\A08[0-9]{8}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] =~ /\A08[0-9]{8}\z/ 0 0 0
234 0 1
235 }
236  
237 sub is_adult
238 0 ▶{
Subroutine is_adult: not called CC=2 SCAR=17.9
Pod documented
239 0 ▶ return 0 unless _check_line(@_, qr/\A8/);
Branch: 1 branch
BranchTrueFalseTotal
unless _check_line(@_, qr/\A8/) 0 0 0
240 undef
241 0 }
242  
243 sub is_personal
244 0 ▶{
Subroutine is_personal: not called CC=1 SCAR=6.9
Pod documented
245 undef
246 0 }
247  
248 sub is_corporate
249 0 ▶{
Subroutine is_corporate: not called CC=1 SCAR=6.9
Pod documented
250 undef
251 0 }
252  
253 sub is_government
254 0 ▶{
Subroutine is_government: not called CC=1 SCAR=6.9
Pod documented
255 undef
256 0 }
257  
258 sub is_international
259 0 ▶{
Subroutine is_international: not called CC=1 SCAR=6.9
Pod documented
260 undef
261 0 }
262  
263 sub is_network_service
264 54 ▶{
Subroutine is_network_service: called CC=2 SCAR=7.2
Pod documented
265 54 my ($class, $num) = _num(@_);
266 # Les services réseau sont en direct : jamais de préfixe
267 54 ▶ ($num =~ /\A1(?:|[578]|0[0-9]{2}|1(?:[259]|6000|8[0-9]{3}))\z/) ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$num =~ /\A1(?:|[578]|0[0-9]{2}|1(?:[259]|6000|8[0-9]{3}))\z/ ? : 54 0 54
268 }
269  
270 sub areacode
271 0 ▶{
Subroutine areacode: not called CC=1 SCAR=6.9
Pod documented
272 undef
273 0 }
274  
275 sub areaname
276 0 ▶{
Subroutine areaname: not called CC=1 SCAR=6.9
Pod documented
277 undef
278 0 }
279  
280 sub location
281 0 ▶{
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
282 undef
283 0 }
284  
285 sub subscriber
286 152 ▶{
Subroutine subscriber: called CC=2 SCAR=6.9
Pod documented
287 152 my ($class, $num) = _num(@_);
288 152 my @m = ($num =~ $class->RE_SUBSCRIBER);
289 152 ▶ return undef unless @m;
Branch: 1 branch
BranchTrueFalseTotal
unless @m 54 98 152
290 98 @m = grep { defined } @m;
291 98 $m[0];
292 }
293  
294 my %length_to_format = (
295 # 2 => as is
296 2 ▶ 4 => sub { s/\A(..)(..)/$1 $2/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
297 0 ▶ 6 => sub { s/\A(...)(...)/$1 $2/ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
298 0 ▶ 10 => sub { s/(\d\d)(?=.)/$1 /g },
Subroutine __ANON__: not called CC=1 SCAR=6.9
299 0 ▶ 13 => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
300 0 ▶ s/\A(00)(33)(.)(..)(..)(..)(..)\z/+$2 $3 $4 $5 $6 $7/
Branch: 1 branch
BranchTrueFalseTotal
s/\A(00)(33)(.)(..)(..)(..)(..)\z/+$2 $3 $4 $5 $6 $7/ or s/\A(....)(.)(..)(..)(..)(..)\z/+33 $1 $2 $3 $4 $5 $6/ 0 0 0
301 || s/\A(....)(.)(..)(..)(..)(..)\z/+33 $1 $2 $3 $4 $5 $6/
302 },
303 2 ▶ 14 => sub { s/\A(....)(..)(..)(..)(..)(..)\z/$1 $2 $3 $4 $5 $6/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
304 2 ▶ 12 => sub { s/\A(\+33)(.)(..)(..)(..)(..)\z/$1 $2 $3 $4 $5 $6/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
305 0 ▶ 16 => sub { s/\A(\+33)(....)(.)(..)(..)(..)(..)\z/$1 $2 $3 $4 $5 $6 $7/ },
Subroutine __ANON__: not called CC=1 SCAR=6.9
306 12 );
307  
308 sub format
309 6 ▶{
Subroutine format: called CC=2 SCAR=7.0
Pod documented
310 6 my ($class, $num) = _num(@_);
311 6 my $l = length $num;
312 6 my $fmt = $length_to_format{$l};
313 return defined $fmt
314 6 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
defined $fmt ? : 6 0 6
315 6 local $_ = $num;
316 6 $fmt->();
317 6 $_;
318 }
319 : $num;
320 }
321  
322  
323  
324 package Number::Phone::FR::Simple;
325  
326 12 ▶use parent 'Number::Phone::FR';
Subroutine BEGIN: called CC=1 SCAR=0.0
327  
328 12 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
329 12 $INC{'Number/Phone/FR/Simple.pm'} = __FILE__;
330 }
331  
332 12 1;
333 __END__
↑ Summary FR/Full.pm »