blib/lib/DBM/Deep.pm

filter: Statementstmt 100% 687 / 687 Branchbran 83.5% 112 / 134 Conditioncond 70.4% 31 / 44 MC/DCmcdc 55.5% 15 / 27 Subroutinesub 100% 229 / 229 Podpod 100% 26 / 26 totaltotal 95.9% 1100 / 1147 CC 86 SCAR 9.8
CC
86
Cov
96%
_warnif
16.0
__ANON__
13.0
_init
11.0
CRAP 2.7
« blib/lib/DBM/Deep/Sector/File/Scalar.pm ↑ Summary blib/lib/DBM/Deep/Hash.pm »
1 package DBM::Deep;
2  
3 97 ▶use 5.008_004;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 97 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 81 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 61 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 56 our $VERSION = q(2.0017);
10  
11 61 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 use overload
14 (
15 '""' =>
16 95166 ▶ '0+' => sub { $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 58 )[0,2,1,2], # same sub for both
18 59 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 58 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 58 ▶use DBM::Deep::Engine;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3736 ▶sub TYPE_HASH () { DBM::Deep::Engine->SIG_HASH }
Subroutine TYPE_HASH: called CC=1 SCAR=0.0
Pod documented
25 4526 ▶sub TYPE_ARRAY () { DBM::Deep::Engine->SIG_ARRAY }
Subroutine TYPE_ARRAY: called CC=1 SCAR=0.0
Pod documented
26  
27 56 my %obj_cache; # In external_refs mode, all objects are registered here,
28 # and dealt with in the END block at the bottom.
29 58 ▶use constant HAVE_HUFH => scalar eval{ require Hash::Util::FieldHash };
Subroutine BEGIN: called CC=1 SCAR=0.0
30 56 HAVE_HUFH and Hash::Util::FieldHash::fieldhash(%obj_cache);
31  
32 # This is used in all the children of this class in their TIE<type> methods.
33 sub _get_args {
34 5670 ▶ my $proto = shift;
Subroutine _get_args: called CC=6 SCAR=17.9
35  
36 5670 my $args;
37 5670 ▶ if (scalar(@_) > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ > 1) { } 3076 2591 5667
elsif (ref $_[0]) { } 2566 25 2591
38 3079 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 2 3074 3076
39 5 $proto->_throw_error( "Odd number of parameters to " . (caller(1))[2] );
40 }
41 3077 $args = {@_};
42 }
43 elsif ( ref $_[0] ) {
44 2569 ▶ unless ( eval { local $SIG{'__DIE__'}; %{$_[0]} || 1 } ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (eval { do { local $SIG{"__DIE__"}; %{$_[0];} or 1 } }) 2 2564 2566
%{$_[0];} or 1 0 2564 2564
45 5 $proto->_throw_error( "Not a hashref in args to " . (caller(1))[2] );
46 }
47 2567 $args = $_[0];
48 }
49 else {
50 28 $args = { file => shift };
51 }
52  
53 5666 return $args;
54 }
55  
56 # Class constructor method for Perl OO interface.
57 # Calls tie() and returns blessed reference to tied hash or array,
58 # providing a hybrid OO/tie interface.
59 sub new {
60 2719 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
61 2719 my $args = $class->_get_args( @_ );
62 2719 my $self;
63  
64 2719 ▶ if (defined($args->{type}) && $args->{type} eq TYPE_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'type'} and $args->{'type'} eq &TYPE_ARRAY()) { } 2111 605 2716
Condition100%3/3
defined $args->{"type"} and $args->{"type"} eq &TYPE_ARRAY()
!ll&&!rl&&r
3672382111
MC/DC100%2/2
defined $args->{"type"} and $args->{"type"} eq &TYPE_ARRAY()
defined $args->{"type"} $args->{"type"} eq &TYPE_ARRAY()
Truth table100%3/3
A and B
A= defined $args->{"type"}B= $args->{"type"} eq &TYPE_ARRAY()
ABresult
0X0
100
111
65 2114 $class = 'DBM::Deep::Array';
66 2114 require DBM::Deep::Array;
67 2114 tie @$self, $class, %$args;
68 }
69 else {
70 608 $class = 'DBM::Deep::Hash';
71 608 require DBM::Deep::Hash;
72 608 tie %$self, $class, %$args;
73 }
74  
75 2707 return bless $self, $class;
76 }
77  
78 # This initializer is called from the various TIE* methods. new() calls tie(),
79 # which allows for a single point of entry.
80 sub _init {
81 2950 ▶ my $class = shift;
Subroutine _init: called CC=11 SCAR=24.0
82 2950 my ($args) = @_;
83  
84 # locking implicitly enables autoflush
85 2950 ▶ if ($args->{locking}) { $args->{autoflush} = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"locking"}) 21 2926 2947
86  
87 # These are the defaults to be optionally overridden below
88 2950 my $self = bless {
89 type => TYPE_HASH,
90 base_offset => undef,
91 staleness => undef,
92 engine => undef,
93 }, $class;
94  
95 2950 ▶ unless ( exists $args->{engine} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args->{"engine"}) 396 2551 2947
96 my $class =
97 exists $args->{dbi} ? 'DBM::Deep::Engine::DBI' :
98 399 ▶ exists $args->{_test} ? 'DBM::Deep::Engine::Test' :
Branch: 2 branches
BranchTrueFalseTotal
exists $args->{'dbi'} ? : 0 396 396
exists $args->{'_test'} ? : 5 391 396
99 'DBM::Deep::Engine::File' ;
100  
101 57 ▶ eval "use $class"; die $@ if $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 396 396
102 $args->{engine} = $class->new({
103 397 %{$args},
104 obj => $self,
105 });
106 }
107  
108 # Grab the parameters we want to use
109 2947 foreach my $param ( keys %$self ) {
110 11785 ▶ next unless exists $args->{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{$param} 790 10994 11784
111 10995 $self->{$param} = $args->{$param};
112 }
113  
114 2947 eval {
115 2947 local $SIG{'__DIE__'};
116  
117 2947 $self->lock_exclusive;
118 2946 $self->_engine->setup( $self );
119 2934 $self->unlock;
120 2947 ▶ }; if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 15 2931 2946
121 16 my $e = $@;
122 16 eval { local $SIG{'__DIE__'}; $self->unlock; };
123 16 die $e;
124 }
125  
126 2932 ▶ if( $self->{engine}->{external_refs}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"engine"}{"external_refs"} and my $sector = $self->{"engine"}->load_sector($self->{"base_offset"})) 22 2909 2931
Condition66%2/3
$self->{"engine"}{"external_refs"} and my $sector = $self->{"engine"}->load_sector($self->{"base_offset"})
!ll&&!rl&&r
2909022
MC/DC50%1/2
$self->{"engine"}{"external_refs"} and my $sector = $self->{"engine"}->load_sector($self->{"base_offset"})
$self->{"engine"}{"external_refs"} my $sector = $self->{"engine"}->load_sector($self->{"base_offset"})
Truth table66%2/3
A and B
A= $self->{"engine"}{"external_refs"}B= my $sector = $self->{"engine"}->load_sector($self->{"base_offset"})
ABresult
0X0
100
111
127 and my $sector = $self->{engine}->load_sector( $self->{base_offset} )
128 ) {
129 23 $sector->increment_refcount;
130  
131 23 Scalar::Util::weaken( my $feeble_ref = $self );
132 23 $obj_cache{ $self } = \$feeble_ref;
133  
134 # Make sure this cache is not a memory hog
135 23 if(!HAVE_HUFH) {
136 for(keys %obj_cache) {
137 delete $obj_cache{$_} if not ${$obj_cache{$_}};
138 }
139 }
140 }
141  
142 2932 return $self;
143 }
144  
145 sub TIEHASH {
146 181 ▶ shift;
Subroutine TIEHASH: called CC=1 SCAR=0.0
147 181 require DBM::Deep::Hash;
148 181 return DBM::Deep::Hash->TIEHASH( @_ );
149 }
150  
151 sub TIEARRAY {
152 56 ▶ shift;
Subroutine TIEARRAY: called CC=1 SCAR=0.0
153 56 require DBM::Deep::Array;
154 56 return DBM::Deep::Array->TIEARRAY( @_ );
155 }
156  
157 sub lock_exclusive {
158 5904 ▶ my $self = shift->_get_self;
Subroutine lock_exclusive: called CC=1 SCAR=0.0
Pod documented
159 5904 return $self->_engine->lock_exclusive( $self, @_ );
160 }
161 56 *lock = \&lock_exclusive;
162  
163 sub lock_shared {
164 4654 ▶ my $self = shift->_get_self;
Subroutine lock_shared: called CC=2 SCAR=7.0
Pod documented
165 # cluck() the problem with cached File objects.
166 4654 ▶ unless ( $self->_engine ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_engine) 0 4653 4653
167 1 require Carp;
168 1 require Data::Dumper;
169 1 Carp::cluck( Data::Dumper->Dump( [$self], ['self'] ) );
170 }
171 4654 return $self->_engine->lock_shared( $self, @_ );
172 }
173  
174 sub unlock {
175 10552 ▶ my $self = shift->_get_self;
Subroutine unlock: called CC=1 SCAR=0.0
Pod documented
176 10552 return $self->_engine->unlock( $self, @_ );
177 }
178  
179 sub _copy_value {
180 72 ▶ my $self = shift->_get_self;
Subroutine _copy_value: called CC=8 SCAR=20.9
181 72 my ($spot, $value) = @_;
182  
183 72 ▶ if ( !ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $value) { } 39 32 71
184 40 ${$spot} = $value;
185 }
186 else {
187 33 my $r = Scalar::Util::reftype( $value );
188 33 my $tied;
189 33 ▶ if ( $r eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r eq 'ARRAY') { } 19 13 32
elsif ($r eq 'HASH') { } 13 0 13
190 20 $tied = tied(@$value);
191 }
192 elsif ( $r eq 'HASH' ) {
193 14 $tied = tied(%$value);
194 }
195 else {
196 1 __PACKAGE__->_throw_error( "Unknown type for '$value'" );
197 }
198  
199 33 ▶ if ( eval { local $SIG{'__DIE__'}; $tied->isa( __PACKAGE__ ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { local $SIG{'__DIE__'}; $tied->isa(__PACKAGE__) } }) { } 32 0 32
200 33 ${$spot} = $tied->_repr;
201 33 $tied->_copy_node( ${$spot} );
202 }
203 else {
204 1 ▶ if ( $r eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r eq 'ARRAY') { } 0 0 0
205 1 ${$spot} = [ @{$value} ];
206 }
207 else {
208 1 ${$spot} = { %{$value} };
209 }
210 }
211  
212 33 my $c = Scalar::Util::blessed( $value );
213 33 ▶ if ( defined $c && !$c->isa( __PACKAGE__ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and not $c->isa(__PACKAGE__)) 16 16 32
Condition66%2/3
defined $c and not $c->isa(__PACKAGE__)
!ll&&!rl&&r
01616
MC/DC50%1/2
defined $c and not $c->isa(__PACKAGE__)
defined $c not $c->isa(__PACKAGE__)
Truth table66%2/3
A and not(B)
A= defined $cB= not $c->isa(__PACKAGE__)
ABresult
0X0
100
111
214 17 ${$spot} = bless ${$spot}, $c
215 }
216 }
217  
218 72 return 1;
219 }
220  
221 sub export {
222 13 ▶ my $self = shift->_get_self;
Subroutine export: called CC=2 SCAR=6.9
Pod documented
223  
224 13 my $temp = $self->_repr;
225  
226 13 $self->lock_exclusive;
227 13 $self->_copy_node( $temp );
228 13 $self->unlock;
229  
230 13 my $classname = $self->_engine->get_classname( $self );
231 13 ▶ if ( defined $classname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $classname) 4 8 12
232 5 bless $temp, $classname;
233 }
234  
235 13 return $temp;
236 }
237  
238 sub _check_legality {
239 110 ▶ my $self = shift;
Subroutine _check_legality: called CC=5 SCAR=16.1
240 110 my ($val) = @_;
241  
242 110 my $r = Scalar::Util::reftype( $val );
243  
244 110 ▶ return $r if !defined $r || '' eq $r;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $r or "" eq $r 38 71 109
Condition66%2/3
not defined $r or "" eq $r
l!l&&r!l&&!r
38071
MC/DC50%1/2
not defined $r or "" eq $r
not defined $r "" eq $r
Truth table66%2/3
not(A) or B
A= not defined $rB= "" eq $r
ABresult
1X1
011
000
245 72 ▶ return $r if 'HASH' eq $r;
Branch: 1 branch
BranchTrueFalseTotal
if "HASH" eq $r 35 36 71
246 37 ▶ return $r if 'ARRAY' eq $r;
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" eq $r 33 3 36
247  
248 4 __PACKAGE__->_throw_error(
249 "Storage of references of type '$r' is not supported."
250 );
251 }
252  
253 sub import {
254 66 ▶ return if !ref $_[0]; # Perl calls import() on use -- ignore
Subroutine import: called CC=6 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 53 12 65
255  
256 13 my $self = shift->_get_self;
257 13 my ($struct) = @_;
258  
259 13 my $type = $self->_check_legality( $struct );
260 13 ▶ if ( !$type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 2 10 12
261 3 __PACKAGE__->_throw_error( "Cannot import a scalar" );
262 }
263  
264 11 ▶ if ( substr( $type, 0, 1 ) ne $self->_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($type, 0, 1) ne $self->_type) 2 8 10
265 3 ▶ __PACKAGE__->_throw_error(
Branch: 2 branches
BranchTrueFalseTotal
'HASH' eq $type ? : 1 1 2
'HASH' eq $type ? : 1 1 2
266 "Cannot import " . ('HASH' eq $type ? 'a hash' : 'an array')
267 . " into " . ('HASH' eq $type ? 'an array' : 'a hash')
268 );
269 }
270  
271 9 my %seen;
272 my $recurse;
273 $recurse = sub {
274 34 ▶ my ($db, $val) = @_;
Subroutine __ANON__: called CC=13 SCAR=25.7
275  
276 34 ▶ my $obj = 'HASH' eq Scalar::Util::reftype( $db ) ? tied(%$db) : tied(@$db);
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq builtin::reftype($db) ? : 19 14 33
277 34 ▶ $obj ||= $db;
Condition66%2/3
$obj ||= $db
l!l&&r!l&&!r
2580
MC/DC0%0/2
$obj ||= $db
$obj $db
Truth table66%2/3
A ||= B
A= $objB= $db
ABresult
1X1
011
000
278  
279 34 my $r = $self->_check_legality( $val );
280 34 ▶ if ( 'HASH' eq $r ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('HASH' eq $r) { } 17 16 33
elsif ('ARRAY' eq $r) { } 16 0 16
281 18 ▶ while ( my ($k, $v) = each %$val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$val) 35 15 50
282 36 my $r = $self->_check_legality( $v );
283 35 ▶ if ( $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 18 16 34
284 19 ▶ my $temp = 'HASH' eq $r ? {} : [];
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq $r ? : 9 9 18
285 19 ▶ if ( my $c = Scalar::Util::blessed( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = builtin::blessed($v)) 8 10 18
286 9 bless $temp, $c;
287 }
288 19 $obj->put( $k, $temp );
289 19 $recurse->( $temp, $v );
290 }
291 else {
292 17 $obj->put( $k, $v );
293 }
294 }
295 }
296 elsif ( 'ARRAY' eq $r ) {
297 17 foreach my $k ( 0 .. $#$val ) {
298 30 my $v = $val->[$k];
299 30 my $r = $self->_check_legality( $v );
300 28 ▶ if ( $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 7 20 27
301 8 ▶ my $temp = 'HASH' eq $r ? {} : [];
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq $r ? : 2 5 7
302 8 ▶ if ( my $c = Scalar::Util::blessed( $v ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = builtin::blessed($v)) 3 4 7
303 4 bless $temp, $c;
304 }
305 8 $obj->put( $k, $temp );
306 8 $recurse->( $temp, $v );
307 }
308 else {
309 21 $obj->put( $k, $v );
310 }
311 }
312 }
313 9 };
314 9 $recurse->( $self, $struct );
315  
316 6 return 1;
317 }
318  
319 #XXX Need to keep track of who has a fh to this file in order to
320 #XXX close them all prior to optimize on Win32/cygwin
321 # Rebuild entire database into new file, then move
322 # it back on top of original.
323 sub optimize {
324 3 ▶ my $self = shift->_get_self;
Subroutine optimize: called CC=5 SCAR=16.2
Pod documented
325  
326 # Optimizing is only something we need to do when we're working with our
327 # own file format. Otherwise, let the other guy do the optimizations.
328 3 ▶ return unless $self->_engine->isa( 'DBM::Deep::Engine::File' );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_engine->isa("DBM::Deep::Engine::File") 0 2 2
329  
330 #XXX Need to create a new test for this
331 # if ($self->_engine->storage->{links} > 1) {
332 # $self->_throw_error("Cannot optimize: reference count is greater than 1");
333 # }
334  
335 #XXX Do we have to lock the tempfile?
336  
337 #XXX Should we use tempfile() here instead of a hard-coded name?
338 3 my $temp_filename = $self->_engine->storage->{file} . '.tmp';
339 my $db_temp = __PACKAGE__->new(
340 file => $temp_filename,
341 type => $self->_type,
342  
343 # Bring over all the parameters that we need to bring over
344 3 ( map { $_ => $self->_engine->$_ } qw(
345 byte_size max_buckets data_sector_size num_txns
346 )),
347 );
348  
349 3 $self->lock_exclusive;
350 3 $self->_engine->clear_cache;
351 3 $self->_copy_node( $db_temp );
352 3 $self->unlock;
353 3 $db_temp->_engine->storage->close;
354 3 undef $db_temp;
355  
356 ##
357 # Attempt to copy user, group and permissions over to new file
358 ##
359 3 $self->_engine->storage->copy_stats( $temp_filename );
360  
361 # q.v. perlport for more information on this variable
362 3 ▶ if ( $^O eq 'MSWin32' || $^O eq 'cygwin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32" or $^O eq "cygwin") 0 2 2
Condition33%1/3
$^O eq "MSWin32" or $^O eq "cygwin"
l!l&&r!l&&!r
002
MC/DC0%0/2
$^O eq "MSWin32" or $^O eq "cygwin"
$^O eq "MSWin32" $^O eq "cygwin"
Truth table33%1/3
A or B
A= $^O eq "MSWin32"B= $^O eq "cygwin"
ABresult
1X1
011
000
363 ##
364 # Potential race condition when optimizing on Win32 with locking.
365 # The Windows filesystem requires that the filehandle be closed
366 # before it is overwritten with rename(). This could be redone
367 # with a soft copy.
368 ##
369 1 $self->unlock;
370 1 $self->_engine->storage->close;
371 }
372  
373 3 ▶ if (!rename $temp_filename, $self->_engine->storage->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rename $temp_filename, $self->_engine->storage->{"file"}) 0 2 2
374 1 unlink $temp_filename;
375 1 $self->unlock;
376 1 $self->_throw_error("Optimize failed: Cannot copy temp file over original: $!");
377 }
378  
379 3 $self->unlock;
380 3 $self->_engine->storage->close;
381  
382 3 $self->_engine->storage->open;
383 3 $self->lock_exclusive;
384 3 $self->_engine->setup( $self );
385 3 $self->unlock;
386  
387 3 return 1;
388 }
389  
390 sub clone {
391 2 ▶ my $self = shift->_get_self;
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
392  
393 2 return __PACKAGE__->new(
394 type => $self->_type,
395 base_offset => $self->_base_offset,
396 staleness => $self->_staleness,
397 engine => $self->_engine,
398 );
399 }
400  
401 sub supports {
402 13 ▶ my $self = shift->_get_self;
Subroutine supports: called CC=1 SCAR=0.0
Pod documented
403 13 return $self->_engine->supports( @_ );
404 }
405  
406 sub db_version {
407 3 ▶ shift->_get_self->_engine->db_version;
Subroutine db_version: called CC=1 SCAR=0.0
Pod documented
408 }
409  
410 #XXX Migrate this to the engine, where it really belongs and go through some
411 # API - stop poking in the innards of someone else..
412 {
413 my %is_legal_filter = map {
414 56 $_ => ~~1,
415 } qw(
416 store_key store_value
417 fetch_key fetch_value
418 );
419  
420 sub set_filter {
421 10 ▶ my $self = shift->_get_self;
Subroutine set_filter: called CC=2 SCAR=6.9
Pod documented
422 10 my $type = lc shift;
423 10 my $func = shift;
424  
425 10 ▶ if ( $is_legal_filter{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_legal_filter{$type}) 8 1 9
426 9 $self->_engine->storage->{"filter_$type"} = $func;
427 9 return 1;
428 }
429  
430 2 return;
431 }
432  
433 2 ▶ sub filter_store_key { $_[0]->set_filter( store_key => $_[1] ); }
Subroutine filter_store_key: called CC=1 SCAR=0.0
Pod documented
434 2 ▶ sub filter_store_value { $_[0]->set_filter( store_value => $_[1] ); }
Subroutine filter_store_value: called CC=1 SCAR=0.0
Pod documented
435 2 ▶ sub filter_fetch_key { $_[0]->set_filter( fetch_key => $_[1] ); }
Subroutine filter_fetch_key: called CC=1 SCAR=0.0
Pod documented
436 2 ▶ sub filter_fetch_value { $_[0]->set_filter( fetch_value => $_[1] ); }
Subroutine filter_fetch_value: called CC=1 SCAR=0.0
Pod documented
437 }
438  
439 56 sub begin_work {
440 278 ▶ my $self = shift->_get_self;
Subroutine begin_work: called CC=2 SCAR=6.9
Pod documented
441 278 $self->lock_exclusive;
442 278 my $rv = eval {
443 278 local $SIG{'__DIE__'};
444 278 $self->_engine->begin_work( $self, @_ );
445 };
446 278 my $e = $@;
447 278 $self->unlock;
448 278 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 2 275 277
449 276 return $rv;
450 }
451  
452 sub rollback {
453 15 ▶ my $self = shift->_get_self;
Subroutine rollback: called CC=2 SCAR=6.9
Pod documented
454  
455 15 $self->lock_exclusive;
456 15 my $rv = eval {
457 15 local $SIG{'__DIE__'};
458 15 $self->_engine->rollback( $self, @_ );
459 };
460 15 my $e = $@;
461 15 $self->unlock;
462 15 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 2 12 14
463 13 return $rv;
464 }
465  
466 sub commit {
467 13 ▶ my $self = shift->_get_self;
Subroutine commit: called CC=2 SCAR=6.9
Pod documented
468 13 $self->lock_exclusive;
469 13 my $rv = eval {
470 13 local $SIG{'__DIE__'};
471 13 $self->_engine->commit( $self, @_ );
472 };
473 13 my $e = $@;
474 13 $self->unlock;
475 13 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 2 10 12
476 11 return $rv;
477 }
478  
479 # Accessor methods
480 sub _engine {
481 45984 ▶ my $self = $_[0]->_get_self;
Subroutine _engine: called CC=1 SCAR=0.0
482 45984 return $self->{engine};
483 }
484  
485 sub _type {
486 399 ▶ my $self = $_[0]->_get_self;
Subroutine _type: called CC=1 SCAR=0.0
487 399 return $self->{type};
488 }
489  
490 sub _base_offset {
491 10844 ▶ my $self = $_[0]->_get_self;
Subroutine _base_offset: called CC=1 SCAR=0.0
492 10844 return $self->{base_offset};
493 }
494  
495 sub _staleness {
496 5573 ▶ my $self = $_[0]->_get_self;
Subroutine _staleness: called CC=1 SCAR=0.0
497 5573 return $self->{staleness};
498 }
499  
500 # Utility methods
501 sub _throw_error {
502 56 ▶ my $n = 0;
Subroutine _throw_error: called CC=2 SCAR=6.9
503 56 while( 1 ) {
504 175 my @caller = caller( ++$n );
505 175 ▶ next if $caller[0] =~ m/^DBM::Deep/;
Branch: 1 branch
BranchTrueFalseTotal
if $caller[0] =~ /^DBM::Deep/ 119 55 174
506  
507 56 die "DBM::Deep: $_[1] at $caller[1] line $caller[2]\n";
508 }
509 }
510  
511 # Store single hash key/value or array element in database.
512 sub STORE {
513 1827 ▶ my $self = shift->_get_self;
Subroutine STORE: called CC=5 SCAR=16.1
514 1827 my ($key, $value) = @_;
515 1827 warn "STORE($self, '$key', '@{[defined$value?$value:'undef']}')\n" if DEBUG;
516  
517 1827 ▶ unless ( $self->_engine->storage->is_writable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_engine->storage->is_writable) 2 1823 1825
518 3 $self->_throw_error( 'Cannot write to a readonly filehandle' );
519 }
520  
521 1824 $self->lock_exclusive;
522  
523 # User may be storing a complex value, in which case we do not want it run
524 # through the filtering system.
525 1824 ▶ if ( !ref($value) && $self->_engine->storage->{filter_store_value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $value and $self->_engine->storage->{"filter_store_value"}) 2 1821 1823
Condition100%3/3
not ref $value and $self->_engine->storage->{"filter_store_value"}
!ll&&!rl&&r
12395822
MC/DC100%2/2
not ref $value and $self->_engine->storage->{"filter_store_value"}
not ref $value $self->_engine->storage->{"filter_store_value"}
Truth table100%3/3
not(A) and B
A= not ref $valueB= $self->_engine->storage->{"filter_store_value"}
ABresult
0X0
100
111
526 3 $value = $self->_engine->storage->{filter_store_value}->( $value );
527 }
528  
529 1824 eval {
530 1824 local $SIG{'__DIE__'};
531 1824 $self->_engine->write_value( $self, $key, $value );
532 1824 ▶ }; if ( my $e = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@) 12 1811 1823
533 13 $self->unlock;
534 13 die $e;
535 }
536  
537 1812 $self->unlock;
538  
539 1812 return 1;
540 }
541  
542 # Fetch single value or element given plain key or array index
543 sub FETCH {
544 3146 ▶ my $self = shift->_get_self;
Subroutine FETCH: called CC=4 SCAR=13.9
545 3146 my ($key) = @_;
546 3146 warn "FETCH($self, '$key')\n" if DEBUG;
547  
548 3146 $self->lock_shared;
549  
550 3146 my $result = $self->_engine->read_value( $self, $key );
551  
552 3145 $self->unlock;
553  
554 # Filters only apply to scalar values, so the ref check is making
555 # sure the fetched bucket is a scalar, not a child hash or array.
556 return ($result && !ref($result) && $self->_engine->storage->{filter_fetch_value})
557 3145 ▶ ? $self->_engine->storage->{filter_fetch_value}->($result)
Branch: 1 branch
BranchTrueFalseTotal
$result && !ref($result) && $self->_engine->storage->{'filter_fetch_value'} ? : 2 3142 3144
Condition100%6/6
$result and not ref $result and $self->_engine->storage->{"filter_fetch_value"}
!ll&&!rl&&r
24327102
$result and not ref $result
!ll&&!rl&&r
932339712
MC/DC100%3/3
$result and not ref $result and $self->_engine->storage->{"filter_fetch_value"}
$result not ref $result $self->_engine->storage->{"filter_fetch_value"}
Truth table100%4/4
A and not(B) and C
A= $resultB= not ref $resultC= $self->_engine->storage->{"filter_fetch_value"}
ABCresult
0XX0
10X0
1100
1111
558 : $result;
559 }
560  
561 # Delete single key/value pair or element given plain key or array index
562 sub DELETE {
563 63 ▶ my $self = shift->_get_self;
Subroutine DELETE: called CC=5 SCAR=16.1
564 63 my ($key) = @_;
565 63 warn "DELETE($self, '$key')\n" if DEBUG;
566  
567 63 ▶ unless ( $self->_engine->storage->is_writable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_engine->storage->is_writable) 1 61 62
568 2 $self->_throw_error( 'Cannot write to a readonly filehandle' );
569 }
570  
571 62 $self->lock_exclusive;
572  
573 ##
574 # Delete bucket
575 ##
576 62 my $value = $self->_engine->delete_key( $self, $key);
577  
578 61 ▶ if (defined $value && !ref($value) && $self->_engine->storage->{filter_fetch_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and not ref $value and $self->_engine->storage->{"filter_fetch_value"}) 1 59 60
Condition100%6/6
defined $value and not ref $value and $self->_engine->storage->{"filter_fetch_value"}
!ll&&!rl&&r
29301
defined $value and not ref $value
!ll&&!rl&&r
131631
MC/DC100%3/3
defined $value and not ref $value and $self->_engine->storage->{"filter_fetch_value"}
defined $value not ref $value $self->_engine->storage->{"filter_fetch_value"}
Truth table100%4/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $self->_engine->storage->{"filter_fetch_value"}
ABCresult
0XX0
10X0
1100
1111
579 2 $value = $self->_engine->storage->{filter_fetch_value}->($value);
580 }
581  
582 61 $self->unlock;
583  
584 61 return $value;
585 }
586  
587 # Check if a single key or element exists given plain key or array index
588 sub EXISTS {
589 130 ▶ my $self = shift->_get_self;
Subroutine EXISTS: called CC=1 SCAR=0.0
590 130 my ($key) = @_;
591 130 warn "EXISTS($self, '$key')\n" if DEBUG;
592  
593 130 $self->lock_shared;
594  
595 130 my $result = $self->_engine->key_exists( $self, $key );
596  
597 129 $self->unlock;
598  
599 129 return $result;
600 }
601  
602 # Clear all keys from hash, or all elements from array.
603 sub CLEAR {
604 229 ▶ my $self = shift->_get_self;
Subroutine CLEAR: called CC=5 SCAR=16.1
605 229 warn "CLEAR($self)\n" if DEBUG;
606  
607 229 my $engine = $self->_engine;
608 229 ▶ unless ( $engine->storage->is_writable ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($engine->storage->is_writable) 1 227 228
609 2 $self->_throw_error( 'Cannot write to a readonly filehandle' );
610 }
611  
612 228 $self->lock_exclusive;
613 228 eval {
614 228 local $SIG{'__DIE__'};
615 228 $engine->clear( $self );
616 };
617 228 my $e = $@;
618 228 ▶ warn "$e\n" if $e && DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $e and 0 0 227 227
Condition100%2/2
$e and 0
!ll
2261
MC/DC100%1/1
$e and 0
$e
Truth table100%2/2
A
A= $e
Aresult
00
11
619  
620 228 $self->unlock;
621  
622 228 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 1 226 227
623  
624 227 return 1;
625 }
626  
627 # Public method aliases
628 77 ▶sub put { (shift)->STORE( @_ ) }
Subroutine put: called CC=1 SCAR=0.0
Pod documented
629 97 ▶sub get { (shift)->FETCH( @_ ) }
Subroutine get: called CC=1 SCAR=0.0
Pod documented
630 11 ▶sub store { (shift)->STORE( @_ ) }
Subroutine store: called CC=1 SCAR=0.0
Pod documented
631 21 ▶sub fetch { (shift)->FETCH( @_ ) }
Subroutine fetch: called CC=1 SCAR=0.0
Pod documented
632 13 ▶sub delete { (shift)->DELETE( @_ ) }
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
633 17 ▶sub exists { (shift)->EXISTS( @_ ) }
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
634 10 ▶sub clear { (shift)->CLEAR( @_ ) }
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
635  
636 4 ▶sub _dump_file {shift->_get_self->_engine->_dump_file;}
Subroutine _dump_file: called CC=1 SCAR=0.0
637  
638 sub _warnif {
639 4 ▶ my $level;
Subroutine _warnif: called CC=8 SCAR=27.7
640 {
641 4 my($pack, $file, $line, $bitmask) = (caller $level++)[0..2,9];
642 16 ▶ redo if $pack =~ /^DBM::Deep(?:::|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $pack =~ /^DBM::Deep(?:::|\z)/ 12 3 15
643 4 ▶ if(defined &warnings::warnif_at_level) { # perl >= 5.27.8
Branch: 1 branch
BranchTrueFalseTotal
if (defined &warnings::warnif_at_level) { } 3 0 3
644 4 warnings::warnif_at_level($_[0], $level-1, $_[1]);
645 } else {
646 # In older perl versions (< 5.27.8) there is, unfortunately, no way
647 # to avoid this hack. warnings.pm did not allow us to specify
648 # exactly the call frame we want, so we have to look at the bitmask
649 # ourselves.
650 1 ▶ if( vec $bitmask, $warnings::Offsets{$_[0]}, 1,
Branch: 1 branch
BranchTrueFalseTotal
if (vec $bitmask, $warnings::Offsets{$_[0]}, 1 or vec $bitmask, $warnings::Offsets{"all"}, 1) 0 0 0
Condition0%0/3
vec $bitmask, $warnings::Offsets{$_[0]}, 1 or vec $bitmask, $warnings::Offsets{"all"}, 1
l!l&&r!l&&!r
000
MC/DC0%0/2
vec $bitmask, $warnings::Offsets{$_[0]}, 1 or vec $bitmask, $warnings::Offsets{"all"}, 1
vec $bitmask, $warnings::Offsets{$_[0]}, 1 vec $bitmask, $warnings::Offsets{"all"}, 1
Truth table0%0/3
A or B
A= vec $bitmask, $warnings::Offsets{$_[0]}, 1B= vec $bitmask, $warnings::Offsets{"all"}, 1
ABresult
1X1
011
000
651 || vec $bitmask, $warnings::Offsets{all}, 1,
652 ) {
653 1 ▶ my $msg = $_[1] =~ /\n\z/ ? $_[1] : "$_[1] at $file line $line.\n";
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /\n\z/ ? : 0 0 0
654 die $msg
655 if vec $bitmask, $warnings::Offsets{$_[0]}+1, 1,
656 1 ▶ || vec $bitmask, $warnings::Offsets{all}+1, 1;
Branch: 1 branch
BranchTrueFalseTotal
if vec $bitmask, $warnings::Offsets{$_[0]} + 1, 1 or vec $bitmask, $warnings::Offsets{"all"} + 1, 1 0 0 0
Condition0%0/3
vec $bitmask, $warnings::Offsets{$_[0]} + 1, 1 or vec $bitmask, $warnings::Offsets{"all"} + 1, 1
l!l&&r!l&&!r
000
MC/DC0%0/2
vec $bitmask, $warnings::Offsets{$_[0]} + 1, 1 or vec $bitmask, $warnings::Offsets{"all"} + 1, 1
vec $bitmask, $warnings::Offsets{$_[0]} + 1, 1 vec $bitmask, $warnings::Offsets{"all"} + 1, 1
Truth table0%0/3
A or B
A= vec $bitmask, $warnings::Offsets{$_[0]} + 1, 1B= vec $bitmask, $warnings::Offsets{"all"} + 1, 1
ABresult
1X1
011
000
657 1 warn $msg;
658 }
659 }
660 }
661 }
662  
663 sub _free {
664 23 ▶ my $self = shift;
Subroutine _free: called CC=2 SCAR=7.1
665 23 ▶ if(my $sector = $self->{engine}->load_sector( $self->{base_offset} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sector = $self->{"engine"}->load_sector($self->{"base_offset"})) 22 0 22
666 23 $sector->free;
667 }
668 }
669  
670 sub DESTROY {
671 5791 ▶ my $self = shift;
Subroutine DESTROY: called CC=5 SCAR=16.1
672 5791 my $alter_ego = $self->_get_self;
673 5791 ▶ if( !$alter_ego || $self != $alter_ego ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $alter_ego or $self != $alter_ego) 2855 2935 5790
Condition66%2/3
not $alter_ego or $self != $alter_ego
l!l&&r!l&&!r
028552935
MC/DC50%1/2
not $alter_ego or $self != $alter_ego
not $alter_ego $self != $alter_ego
Truth table66%2/3
not(A) or B
A= not $alter_egoB= $self != $alter_ego
ABresult
1X1
011
000
674 2856 return; # Don’t run the destructor twice! (What follows only applies to
675 } # the inner object, not the tie.)
676  
677 # If the engine is gone, the END block has beaten us to it.
678 2936 ▶ return if !$self->{engine};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"engine"} 1 2934 2935
679 2935 ▶ if( $self->{engine}->{external_refs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"engine"}{"external_refs"}) 18 2916 2934
680 19 $self->_free;
681 }
682 }
683  
684 # Relying on the destructor alone is problematic, as the order in which
685 # objects are discarded is random in global destruction. So we do the
686 # clean-up here before preemptively before global destruction.
687 END {
688 defined $$_ and $$_->_free, delete $$_->{engine}
689 56 ▶ for(values %obj_cache);
Subroutine END: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
defined $$_ and $$_->_free, delete $$_->{"engine"} 4 0 4
690 }
691  
692 56 1;
693 __END__
« blib/lib/DBM/Deep/Sector/File/Scalar.pm ↑ Summary blib/lib/DBM/Deep/Hash.pm »