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

filter: Statementstmt 82.0% 32 / 39 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 5 totaltotal 63.8% 46 / 72 CC 9 SCAR 14.4
CC
9
Cov
73%
free
12.0
get_entry
3.2
set_entry
3.2
CRAP 4.2
« blib/lib/DBM/Deep/Storage/File.pm ↑ Summary Build »
1 package DBM::Deep::Sector::File::Index;
2  
3 47 ▶use base qw( DBM::Deep::Sector::File );
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 47 my $STALE_SIZE = 2;
6  
7 # Please refer to the pack() documentation for further information
8 47 my %StP = (
9 1 => 'C', # Unsigned char value (no order needed as it's just one byte)
10 2 => 'n', # Unsigned short in "network" (big-endian) order
11 4 => 'N', # Unsigned long in "network" (big-endian) order
12 8 => 'Q', # Usigned quad (no order specified, presumably machine-dependent)
13 );
14  
15 sub _init {
16 4101 ▶ my $self = shift;
Subroutine _init: called CC=2 SCAR=6.9
17  
18 4101 my $engine = $self->engine;
19  
20 4101 ▶ unless ( $self->offset ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->offset) 11 4090 4101
21 11 my $leftover = $self->size - $self->base_size;
22  
23 11 $self->{offset} = $engine->_request_index_sector( $self->size );
24 11 $engine->storage->print_at( $self->offset, $engine->SIG_INDEX ); # Sector type
25 # Skip staleness counter
26 11 $engine->storage->print_at( $self->offset + $self->base_size,
27 chr(0) x $leftover, # Zero-fill the rest
28 );
29 }
30  
31 4101 return $self;
32 }
33  
34 #XXX Change here
35 sub size {
36 24 ▶ my $self = shift;
Subroutine size: called CC=2 SCAR=6.9
Pod undocumented
37 24 ▶ unless ( $self->{size} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"size"}) 13 11 24
38 13 my $e = $self->engine;
39 13 $self->{size} = $self->base_size + $e->byte_size * $e->hash_chars;
40 }
41 24 return $self->{size};
42 }
43  
44 0 ▶sub free_meth { return '_add_free_index_sector' }
Subroutine free_meth: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 sub free {
47 0 ▶ my $self = shift;
Subroutine free: not called CC=3 SCAR=24.8
Pod undocumented
48 0 my $e = $self->engine;
49  
50 0 for my $i ( 0 .. $e->hash_chars - 1 ) {
51 0 ▶ my $l = $self->get_entry( $i ) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $l = $self->get_entry($i) or next 0 0 0
52 0 $e->load_sector( $l )->free;
53 }
54  
55 0 $self->SUPER::free();
56 }
57  
58 sub _loc_for {
59 8610 ▶ my $self = shift;
Subroutine _loc_for: called CC=1 SCAR=0.0
60 8610 my ($idx) = @_;
61 8610 return $self->offset + $self->base_size + $idx * $self->engine->byte_size;
62 }
63  
64 sub get_entry {
65 8168 ▶ my $self = shift;
Subroutine get_entry: called CC=3 SCAR=11.8
Pod undocumented
66 8168 my ($idx) = @_;
67  
68 8168 my $e = $self->engine;
69  
70 8168 ▶ DBM::Deep->_throw_error( "get_entry: Out of range ($idx)" )
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 or $idx >= $e->hash_chars 0 8168 8168
Condition33%1/3
$idx < 0 or $idx >= $e->hash_chars
l!l&&r!l&&!r
008168
MC/DC0%0/2
$idx < 0 or $idx >= $e->hash_chars
$idx < 0 $idx >= $e->hash_chars
Truth table33%1/3
A or B
A= $idx < 0B= $idx >= $e->hash_chars
ABresult
1X1
011
000
71 if $idx < 0 || $idx >= $e->hash_chars;
72  
73 return unpack(
74 8168 $StP{$e->byte_size},
75 $e->storage->read_at( $self->_loc_for( $idx ), $e->byte_size ),
76 );
77 }
78  
79 sub set_entry {
80 442 ▶ my $self = shift;
Subroutine set_entry: called CC=3 SCAR=11.8
Pod undocumented
81 442 my ($idx, $loc) = @_;
82  
83 442 my $e = $self->engine;
84  
85 442 ▶ DBM::Deep->_throw_error( "set_entry: Out of range ($idx)" )
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 or $idx >= $e->hash_chars 0 442 442
Condition33%1/3
$idx < 0 or $idx >= $e->hash_chars
l!l&&r!l&&!r
00442
MC/DC0%0/2
$idx < 0 or $idx >= $e->hash_chars
$idx < 0 $idx >= $e->hash_chars
Truth table33%1/3
A or B
A= $idx < 0B= $idx >= $e->hash_chars
ABresult
1X1
011
000
86 if $idx < 0 || $idx >= $e->hash_chars;
87  
88 $self->engine->storage->print_at(
89 $self->_loc_for( $idx ),
90 442 pack( $StP{$e->byte_size}, $loc ),
91 );
92 }
93  
94 47 1;
95 __END__
« blib/lib/DBM/Deep/Storage/File.pm ↑ Summary Build »