blib/lib/Number/Phone/UK/Data.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 8 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 93.1% 54 / 58 CC 6 SCAR 8.0
CC
6
Cov
98%
db
4.0
slurp
2.0
_slurp
2.0
CRAP 2.2
« blib/lib/Number/Phone/StubCountry/SM.pm ↑ Summary blib/lib/Number/Phone/StubCountry/BL.pm »
1 package Number::Phone::UK::Data;
2  
3 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Number::Phone;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 our $VERSION = "2.0002";
9  
10 16 ▶use Data::CompactReadonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 16 my $file = Number::Phone::_find_data_file('Number-Phone-UK-Data.db');
14  
15 16 my $slurped = 0;
16 16 my $db;
17 16 my $pid = -1;
18  
19 9632 ▶sub db {
Subroutine db: called CC=4 SCAR=13.9
Pod undocumented
20 9632 ▶ return $db if($slurped);
Branch: 1 branch
BranchTrueFalseTotal
if $slurped 2892 6740 9632
21 6740 ▶ if(!$db || $pid != $$) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $db or $pid != $$) 15 6725 6740
Condition66%2/3
not $db or $pid != $$
l!l&&r!l&&!r
1506725
MC/DC50%1/2
not $db or $pid != $$
not $db $pid != $$
Truth table66%2/3
not(A) or B
A= not $dbB= $pid != $$
ABresult
1X1
011
000
22 # we want to re-open the DB if we've forked, because of
23 # https://github.com/DrHyde/perl-modules-Number-Phone/issues/72
24 15 $pid = $$;
25 15 $db = Data::CompactReadonly->read($file, tie => 1, fast_collections => 1);
26 }
27 6740 return $db
28 }
29  
30 2 ▶sub slurp {
Subroutine slurp: called CC=2 SCAR=6.9
Pod undocumented
31 2 ▶ return if($slurped);
Branch: 1 branch
BranchTrueFalseTotal
if $slurped 1 1 2
32 1 $db = _slurp(db());
33 1 $slurped++;
34 }
35  
36 986091 ▶sub _slurp {
Subroutine _slurp: called CC=2 SCAR=6.9
37 986091 my $db = shift;
38 986091 ▶ if(!ref($db)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $db) { } 986076 15 986091
39 986076 return $db
40 } else {
41 return { map {
42 986090 $_ => _slurp($db->{$_})
43 15 } keys(%{$db}) };
44 }
45 }
46  
47 16 1;
« blib/lib/Number/Phone/StubCountry/SM.pm ↑ Summary blib/lib/Number/Phone/StubCountry/BL.pm »