blib/lib/DBM/Deep/Sector/File.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 87.5% 14 / 16 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 4 totaltotal 90.9% 90 / 99 CC 12 SCAR 18.8
CC
12
Cov
95%
load
12.1
free_meth
2.0
BEGIN
1.0
CRAP 6.6
« blib/lib/DBM/Deep/Storage/DBI.pm ↑ Summary blib/lib/DBM/Deep/Array.pm »
1 package DBM::Deep::Sector::File;
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  
8 53 ▶use base qw( DBM::Deep::Sector );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 53 ▶use DBM::Deep::Sector::File::BucketList ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 53 ▶use DBM::Deep::Sector::File::Index ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 53 ▶use DBM::Deep::Sector::File::Null ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 53 ▶use DBM::Deep::Sector::File::Reference ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 53 ▶use DBM::Deep::Sector::File::Scalar ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 53 my $STALE_SIZE = 2;
17  
18 sub base_size {
19 72067 ▶ my $self = shift;
Subroutine base_size: called CC=1 SCAR=0.0
Pod undocumented
20 72067 return $self->engine->SIG_SIZE + $STALE_SIZE;
21 }
22  
23 0 ▶sub free_meth { die "free_meth must be implemented in a child class" }
Subroutine free_meth: not called CC=1 SCAR=6.9
Pod undocumented
24  
25 sub free {
26 504 ▶ my $self = shift;
Subroutine free: called CC=1 SCAR=0.0
Pod undocumented
27  
28 504 my $e = $self->engine;
29  
30 504 $e->storage->print_at( $self->offset, $e->SIG_FREE );
31 # Skip staleness counter
32 504 $e->storage->print_at( $self->offset + $self->base_size,
33 chr(0) x ($self->size - $self->base_size),
34 );
35  
36 504 my $free_meth = $self->free_meth;
37 504 $e->$free_meth( $self->offset, $self->size );
38  
39 504 return;
40 }
41  
42 #=head2 load( $offset )
43 #
44 #This will instantiate and return the sector object that represents the data
45 #found at $offset.
46 #
47 #=cut
48  
49 sub load {
50 23175 ▶ my $self = shift;
Subroutine load: called CC=12 SCAR=24.9
Pod undocumented
51 23175 my ($engine, $offset) = @_;
52  
53 # Add a catch for offset of 0 or 1
54 23175 ▶ return if !$offset || $offset <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if not $offset or $offset <= 1 4 23171 23175
Condition100%3/3
not $offset or $offset <= 1
l!l&&r!l&&!r
2223171
MC/DC100%2/2
not $offset or $offset <= 1
not $offset $offset <= 1
Truth table100%3/3
not(A) or B
A= not $offsetB= $offset <= 1
ABresult
1X1
011
000
55  
56 23171 my $type = $engine->storage->read_at( $offset, 1 );
57 23171 ▶ return if $type eq chr(0);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "\0" 0 23171 23171
58  
59 23171 ▶ if ( $type eq $engine->SIG_ARRAY || $type eq $engine->SIG_HASH ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq $engine->SIG_ARRAY or $type eq $engine->SIG_HASH) { } 9048 14123 23171
elsif ($type eq $engine->SIG_BLIST) { } 5802 8321 14123
elsif ($type eq $engine->SIG_INDEX) { } 4089 4232 8321
elsif ($type eq $engine->SIG_NULL) { } 27 4205 4232
elsif ($type eq $engine->SIG_DATA or $type eq $engine->SIG_UNIDATA) { } 4200 5 4205
elsif ($type eq $engine->SIG_FREE) { } 5 0 5
Condition100%3/3
$type eq $engine->SIG_ARRAY or $type eq $engine->SIG_HASH
l!l&&r!l&&!r
4106494214123
MC/DC100%2/2
$type eq $engine->SIG_ARRAY or $type eq $engine->SIG_HASH
$type eq $engine->SIG_ARRAY $type eq $engine->SIG_HASH
Truth table100%3/3
A or B
A= $type eq $engine->SIG_ARRAYB= $type eq $engine->SIG_HASH
ABresult
1X1
011
000
60 9048 return DBM::Deep::Sector::File::Reference->new({
61 engine => $engine,
62 type => $type,
63 offset => $offset,
64 });
65 }
66 # XXX Don't we need key_md5 here?
67 elsif ( $type eq $engine->SIG_BLIST ) {
68 5802 return DBM::Deep::Sector::File::BucketList->new({
69 engine => $engine,
70 type => $type,
71 offset => $offset,
72 });
73 }
74 elsif ( $type eq $engine->SIG_INDEX ) {
75 4089 return DBM::Deep::Sector::File::Index->new({
76 engine => $engine,
77 type => $type,
78 offset => $offset,
79 });
80 }
81 elsif ( $type eq $engine->SIG_NULL ) {
82 27 return DBM::Deep::Sector::File::Null->new({
83 engine => $engine,
84 type => $type,
85 offset => $offset,
86 });
87 }
88 ▶ elsif ( $type eq $engine->SIG_DATA || $type eq $engine->SIG_UNIDATA ) {
Condition100%3/3
$type eq $engine->SIG_DATA or $type eq $engine->SIG_UNIDATA
l!l&&r!l&&!r
4190105
MC/DC100%2/2
$type eq $engine->SIG_DATA or $type eq $engine->SIG_UNIDATA
$type eq $engine->SIG_DATA $type eq $engine->SIG_UNIDATA
Truth table100%3/3
A or B
A= $type eq $engine->SIG_DATAB= $type eq $engine->SIG_UNIDATA
ABresult
1X1
011
000
89 4200 return DBM::Deep::Sector::File::Scalar->new({
90 engine => $engine,
91 type => $type,
92 offset => $offset,
93 });
94 }
95 # This was deleted from under us, so just return and let the caller figure it out.
96 elsif ( $type eq $engine->SIG_FREE ) {
97 5 return;
98 }
99  
100 0 DBM::Deep->_throw_error( "'$offset': Don't know what to do with type '$type'" );
101 }
102  
103 53 1;
104 __END__
« blib/lib/DBM/Deep/Storage/DBI.pm ↑ Summary blib/lib/DBM/Deep/Array.pm »