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

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