All/DBM.pm

filter: Statementstmt 69.3% 61 / 88 Branchbran 50.0% 17 / 34 Conditioncond 33.3% 3 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 73.6% 14 / 19 Podpod 40.0% 2 / 5 totaltotal 60.8% 98 / 161 CC 22 SCAR 28.8
CC
22
Cov
62%
open
39.1
assert_filepath
4.8
tie_dbm
3.1
CRAP 17.8
↑ Summary All/MLDBM.pm »
1 4 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package IO::All::DBM;
3  
4 4 ▶use IO::All::File -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 field _dbm_list => [];
8 4 field '_dbm_class';
9 4 field _dbm_extra => [];
10  
11 sub dbm {
12 2 ▶ my $self = shift;
Subroutine dbm: called CC=1 SCAR=0.0
Pod documented
13 2 bless $self, __PACKAGE__;
14 2 $self->_dbm_list([@_]);
15 2 return $self;
16 }
17  
18 sub _assert_open {
19 5 ▶ my $self = shift;
Subroutine _assert_open: called CC=2 SCAR=6.9
20 5 ▶ return $self->tied_file
Branch: 1 branch
BranchTrueFalseTotal
if $self->tied_file 3 2 5
21 if $self->tied_file;
22 2 $self->open;
23 }
24  
25 sub assert_filepath {
26 1 ▶ my $self = shift;
Subroutine assert_filepath: called CC=3 SCAR=15.7
Pod undocumented
27 1 $self->SUPER::assert_filepath(@_);
28 1 ▶ if ($self->_rdonly and not -e $self->pathname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_rdonly and not -e $self->pathname) 0 1 1
Condition33%1/3
$self->_rdonly and not -e $self->pathname
!ll&&!rl&&r
100
MC/DC0%0/2
$self->_rdonly and not -e $self->pathname
$self->_rdonly not -e $self->pathname
Truth table33%1/3
A and not(B)
A= $self->_rdonlyB= not -e $self->pathname
ABresult
0X0
100
111
29 0 my $rdwr = $self->_rdwr;
30 0 $self->assert(0)->rdwr(1)->rdonly(0)->open;
31 0 $self->close;
32 0 $self->assert(1)->rdwr($rdwr)->rdonly(1);
33 }
34 }
35  
36 sub open {
37 2 ▶ my $self = shift;
Subroutine open: called CC=17 SCAR=36.7
Pod documented
38 2 $self->is_open(1);
39 2 ▶ return $self->tied_file if $self->tied_file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->tied_file 0 2 2
40 2 ▶ $self->assert_filepath if $self->_assert;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_assert 1 1 2
41 2 my $dbm_list = $self->_dbm_list;
42 2 ▶ my @dbm_list = @$dbm_list ? @$dbm_list :
Branch: 1 branch
BranchTrueFalseTotal
@$dbm_list ? : 1 1 2
43 (qw(DB_File GDBM_File NDBM_File ODBM_File SDBM_File));
44 2 my $dbm_class;
45 2 for my $module (@dbm_list) {
46 6 (my $file = "$module.pm") =~ s{::}{/}g;
47 6 ▶ if (defined $INC{$file} || eval "eval 'use $module; 1'") {
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
if (defined $INC{$file} or eval "eval 'use $module; 1'") 2 4 6
Condition66%2/3
defined $INC{$file} or eval "eval 'use $module; 1'"
l!l&&r!l&&!r
024
MC/DC50%1/2
defined $INC{$file} or eval "eval 'use $module; 1'"
defined $INC{$file} eval "eval 'use $module; 1'"
Truth table66%2/3
A or B
A= defined $INC{$file}B= eval "eval 'use $module; 1'"
ABresult
1X1
011
000
48 2 $self->_dbm_class($module);
49 2 last;
50 }
51 }
52 2 ▶ $self->throw("No module available for IO::All DBM operation")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->_dbm_class 0 2 2
53 unless defined $self->_dbm_class;
54 2 ▶ my $mode = $self->_rdonly ? O_RDONLY : O_RDWR;
Branch: 1 branch
BranchTrueFalseTotal
$self->_rdonly ? : 0 2 2
55 2 ▶ if ($self->_dbm_class eq 'DB_File::Lock') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_dbm_class eq "DB_File::Lock") 0 2 2
56 0 $self->_dbm_class->import;
57 0 ▶ my $type = eval '$DB_HASH'; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
58 # XXX Not sure about this warning
59 0 ▶ warn "Using DB_File::Lock in IO::All without the rdonly or rdwr method\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_rdwr or $self->_rdonly 0 0 0
Condition0%0/3
$self->_rdwr or $self->_rdonly
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_rdwr or $self->_rdonly
$self->_rdwr $self->_rdonly
Truth table0%0/3
A or B
A= $self->_rdwrB= $self->_rdonly
ABresult
1X1
011
000
60 if not ($self->_rdwr or $self->_rdonly);
61 0 ▶ my $flag = $self->_rdwr ? 'write' : 'read';
Branch: 1 branch
BranchTrueFalseTotal
$self->_rdwr ? : 0 0 0
62 0 ▶ $mode = $self->_rdwr ? O_RDWR : O_RDONLY;
Branch: 1 branch
BranchTrueFalseTotal
$self->_rdwr ? : 0 0 0
63 0 $self->_dbm_extra([$type, $flag]);
64 }
65 2 ▶ $mode |= O_CREAT if $mode & O_RDWR;
Branch: 1 branch
BranchTrueFalseTotal
if $mode & 2 2 0 2
66 2 $self->mode($mode);
67 2 ▶ $self->perms(0666) unless defined $self->perms;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->perms 2 0 2
68 2 return $self->tie_dbm;
69 }
70  
71 sub tie_dbm {
72 2 ▶ my $self = shift;
Subroutine tie_dbm: called CC=3 SCAR=11.2
Pod undocumented
73 2 my $hash;
74 2 my $filename = $self->name;
75 my $db = tie %$hash, $self->_dbm_class, $filename, $self->mode, $self->perms,
76 2 ▶ @{$self->_dbm_extra}
Branch: 1 branch
BranchTrueFalseTotal
my $db = tie(%$hash, $self->_dbm_class, $filename, $self->mode, $self->perms, @{$self->_dbm_extra;}) or $self->throw("Can't open '${filename}' as DBM file:\n$!") 0 2 2
77 or $self->throw("Can't open '$filename' as DBM file:\n$!");
78 2 ▶ $self->add_utf8_dbm_filter($db)
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_utf8 0 2 2
79 if $self->_has_utf8;
80 2 $self->tied_file($hash);
81 }
82  
83 sub add_utf8_dbm_filter {
84 0 ▶ my $self = shift;
Subroutine add_utf8_dbm_filter: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my $db = shift;
86 0 ▶ $db->filter_store_key(sub { utf8::encode($_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 ▶ $db->filter_store_value(sub { utf8::encode($_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 ▶ $db->filter_fetch_key(sub { utf8::decode($_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 ▶ $db->filter_fetch_value(sub { utf8::decode($_) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 }
91  
92 4 1;
↑ Summary All/MLDBM.pm »