blib/lib/DBM/Deep/Hash.pm

filter: Statementstmt 100% 67 / 67 Branchbran 96.8% 31 / 32 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 18 / 18 Podpod 100% 2 / 2 totaltotal 99.2% 128 / 129 CC 19 SCAR 9.4
CC
19
Cov
99%
NEXTKEY
4.0
_get_self
3.0
FETCH
3.0
CRAP 2.6
« blib/lib/DBM/Deep.pm ↑ Summary blib/lib/DBM/Deep/Iterator/File/BucketList.pm »
1 package DBM::Deep::Hash;
2  
3 53 ▶use 5.008_004;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 53 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 53 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 53 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 53 ▶use base 'DBM::Deep';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub _get_self {
12 # See the note in Array.pm as to why this is commented out.
13 # eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
14  
15 # During global destruction %{$_[0]} might get tied to undef, so we
16 # need to check that case if tied returns false.
17 63344 ▶ tied %{$_[0]} or local *@, eval { exists $_[0]{_}; 1 } ? $_[0] : undef
Subroutine _get_self: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
tied %{$_[0];} or local *@, eval { do { exists $_[0]{"_"}; 1 } } ? $_[0] : undef 61895 1449 63344
eval { do { exists $_[0]{'_'}; 1 } } ? : 61895 0 61895
18 }
19  
20 21 ▶sub _repr { return {} }
Subroutine _repr: called CC=1 SCAR=0.0
21  
22 sub TIEHASH {
23 785 ▶ my $class = shift;
Subroutine TIEHASH: called CC=1 SCAR=0.0
24 785 my $args = $class->_get_args( @_ );
25
26 783 $args->{type} = $class->TYPE_HASH;
27  
28 783 return $class->_init($args);
29 }
30  
31 sub FETCH {
32 2622 ▶ my $self = shift->_get_self;
Subroutine FETCH: called CC=3 SCAR=11.0
33 2622 ▶ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 2620 2622
34 my $key = ($self->_engine->storage->{filter_store_key})
35 2620 ▶ ? $self->_engine->storage->{filter_store_key}->($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$self->_engine->storage->{'filter_store_key'} ? : 4 2616 2620
36 : $_[0];
37  
38 2620 return $self->SUPER::FETCH( $key, $_[0] );
39 }
40  
41 sub STORE {
42 1512 ▶ my $self = shift->_get_self;
Subroutine STORE: called CC=3 SCAR=11.0
43 1512 ▶ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 1510 1512
44 my $key = ($self->_engine->storage->{filter_store_key})
45 1510 ▶ ? $self->_engine->storage->{filter_store_key}->($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$self->_engine->storage->{'filter_store_key'} ? : 2 1508 1510
46 : $_[0];
47 1510 my $value = $_[1];
48  
49 1510 return $self->SUPER::STORE( $key, $value, $_[0] );
50 }
51  
52 sub EXISTS {
53 125 ▶ my $self = shift->_get_self;
Subroutine EXISTS: called CC=3 SCAR=11.0
54 125 ▶ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 123 125
55 my $key = ($self->_engine->storage->{filter_store_key})
56 123 ▶ ? $self->_engine->storage->{filter_store_key}->($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$self->_engine->storage->{'filter_store_key'} ? : 4 119 123
57 : $_[0];
58  
59 123 return $self->SUPER::EXISTS( $key );
60 }
61  
62 sub DELETE {
63 48 ▶ my $self = shift->_get_self;
Subroutine DELETE: called CC=3 SCAR=11.0
64 48 ▶ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 46 48
65 my $key = ($self->_engine->storage->{filter_store_key})
66 46 ▶ ? $self->_engine->storage->{filter_store_key}->($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$self->_engine->storage->{'filter_store_key'} ? : 1 45 46
67 : $_[0];
68  
69 46 return $self->SUPER::DELETE( $key, $_[0] );
70 }
71  
72 # Locate and return first key (in no particular order)
73 sub FIRSTKEY {
74 162 ▶ my $self = shift->_get_self;
Subroutine FIRSTKEY: called CC=3 SCAR=11.0
75  
76 162 $self->lock_shared;
77
78 162 my $result = $self->_engine->get_next_key( $self );
79
80 159 $self->unlock;
81
82 return ($result && $self->_engine->storage->{filter_fetch_key})
83 159 ▶ ? $self->_engine->storage->{filter_fetch_key}->($result)
Branch: 1 branch
BranchTrueFalseTotal
$result && $self->_engine->storage->{'filter_fetch_key'} ? : 1 158 159
Condition100%3/3
$result and $self->_engine->storage->{"filter_fetch_key"}
!ll&&!rl&&r
121461
MC/DC100%2/2
$result and $self->_engine->storage->{"filter_fetch_key"}
$result $self->_engine->storage->{"filter_fetch_key"}
Truth table100%3/3
A and B
A= $resultB= $self->_engine->storage->{"filter_fetch_key"}
ABresult
0X0
100
111
84 : $result;
85 }
86  
87 # Return next key (in no particular order), given previous one
88 sub NEXTKEY {
89 383 ▶ my $self = shift->_get_self;
Subroutine NEXTKEY: called CC=4 SCAR=13.9
90  
91 my $prev_key = ($self->_engine->storage->{filter_store_key})
92 383 ▶ ? $self->_engine->storage->{filter_store_key}->($_[0])
Branch: 1 branch
BranchTrueFalseTotal
$self->_engine->storage->{'filter_store_key'} ? : 2 381 383
93 : $_[0];
94  
95 383 $self->lock_shared;
96
97 383 my $result = $self->_engine->get_next_key( $self, $prev_key );
98
99 383 $self->unlock;
100
101 return ($result && $self->_engine->storage->{filter_fetch_key})
102 383 ▶ ? $self->_engine->storage->{filter_fetch_key}->($result)
Branch: 1 branch
BranchTrueFalseTotal
$result && $self->_engine->storage->{'filter_fetch_key'} ? : 1 382 383
Condition100%3/3
$result and $self->_engine->storage->{"filter_fetch_key"}
!ll&&!rl&&r
1492331
MC/DC100%2/2
$result and $self->_engine->storage->{"filter_fetch_key"}
$result $self->_engine->storage->{"filter_fetch_key"}
Truth table100%3/3
A and B
A= $resultB= $self->_engine->storage->{"filter_fetch_key"}
ABresult
0X0
100
111
103 : $result;
104 }
105  
106 33 ▶sub first_key { (shift)->FIRSTKEY(@_) }
Subroutine first_key: called CC=1 SCAR=0.0
Pod documented
107 52 ▶sub next_key { (shift)->NEXTKEY(@_) }
Subroutine next_key: called CC=1 SCAR=0.0
Pod documented
108  
109 sub _clear {
110 1 ▶ my $self = shift;
Subroutine _clear: called CC=3 SCAR=11.0
111  
112 1 ▶ while ( defined(my $key = $self->first_key) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $key = $self->first_key)) 1 1 2
113 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined($key = $self->next_key($key)) and do { do { $self->_engine->delete_key($self, $key, $key) } } 1 1 2
114 2 $self->_engine->delete_key( $self, $key, $key );
115 } while defined($key = $self->next_key($key));
116 }
117  
118 1 return;
119 }
120  
121 sub _copy_node {
122 23 ▶ my $self = shift;
Subroutine _copy_node: called CC=2 SCAR=6.9
123 23 my ($db_temp) = @_;
124  
125 23 my $key = $self->first_key();
126 23 ▶ while (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 41 23 64
127 41 my $value = $self->get($key);
128 41 $self->_copy_value( \$db_temp->{$key}, $value );
129 41 $key = $self->next_key($key);
130 }
131  
132 23 return 1;
133 }
134  
135 53 1;
136 __END__
« blib/lib/DBM/Deep.pm ↑ Summary blib/lib/DBM/Deep/Iterator/File/BucketList.pm »