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

filter: Statementstmt 98.3% 60 / 61 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 5 totaltotal 91.8% 79 / 86 CC 6 SCAR 7.3
CC
6
Cov
97%
_init
4.0
free
2.1
data
2.0
CRAP 2.1
« blib/lib/DBM/Deep.pm ↑ Summary blib/lib/DBM/Deep/Iterator/File/BucketList.pm »
1 package DBM::Deep::Sector::File::Scalar;
2  
3 47 ▶use 5.006_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 47 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 47 ▶use base qw( DBM::Deep::Sector::File::Data );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 47 my $STALE_SIZE = 2;
11  
12 # Please refer to the pack() documentation for further information
13 47 my %StP = (
14 1 => 'C', # Unsigned char value (no order needed as it's just one byte)
15 2 => 'n', # Unsigned short in "network" (big-endian) order
16 4 => 'N', # Unsigned long in "network" (big-endian) order
17 8 => 'Q', # Usigned quad (no order specified, presumably machine-dependent)
18 );
19  
20 sub free {
21 355 ▶ my $self = shift;
Subroutine free: called CC=2 SCAR=7.2
Pod undocumented
22  
23 355 my $chain_loc = $self->chain_loc;
24  
25 355 $self->SUPER::free();
26  
27 355 ▶ if ( $chain_loc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chain_loc) 0 355 355
28 0 $self->engine->load_sector( $chain_loc )->free;
29 }
30  
31 355 return;
32 }
33  
34 4548 ▶sub type { $_[0]{engine}->SIG_DATA }
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
35 sub _init {
36 6079 ▶ my $self = shift;
Subroutine _init: called CC=4 SCAR=13.9
37  
38 6079 my $engine = $self->engine;
39  
40 6079 ▶ unless ( $self->offset ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->offset) 2094 3985 6079
41 2094 my $data_section = $self->size - $self->base_size - $engine->byte_size - 1;
42  
43 2094 $self->{offset} = $engine->_request_data_sector( $self->size );
44  
45 2094 my $data = delete $self->{data};
46 2094 my $dlen = length $data;
47 2094 my $continue = 1;
48 2094 my $curr_offset = $self->offset;
49 2094 ▶ while ( $continue ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($continue) 4518 2094 6612
50  
51 4518 my $next_offset = 0;
52  
53 4518 my ($leftover, $this_len, $chunk);
54 4518 ▶ if ( $dlen > $data_section ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dlen > $data_section) { } 2424 2094 4518
55 2424 $leftover = 0;
56 2424 $this_len = $data_section;
57 2424 $chunk = substr( $data, 0, $this_len );
58  
59 2424 $dlen -= $data_section;
60 2424 $next_offset = $engine->_request_data_sector( $self->size );
61 2424 $data = substr( $data, $this_len );
62 }
63 else {
64 2094 $leftover = $data_section - $dlen;
65 2094 $this_len = $dlen;
66 2094 $chunk = $data;
67  
68 2094 $continue = 0;
69 }
70  
71 4518 $engine->storage->print_at( $curr_offset, $self->type ); # Sector type
72 # Skip staleness
73 $engine->storage->print_at( $curr_offset + $self->base_size,
74 pack( $StP{$engine->byte_size}, $next_offset ), # Chain loc
75 4518 pack( $StP{1}, $this_len ), # Data length
76 $chunk, # Data to be stored in this sector
77 chr(0) x $leftover, # Zero-fill the rest
78 );
79  
80 4518 $curr_offset = $next_offset;
81 }
82  
83 2094 return;
84 }
85 }
86  
87 sub data_length {
88 3578 ▶ my $self = shift;
Subroutine data_length: called CC=1 SCAR=0.0
Pod undocumented
89  
90 3578 my $buffer = $self->engine->storage->read_at(
91 $self->offset + $self->base_size + $self->engine->byte_size, 1
92 );
93  
94 3578 return unpack( $StP{1}, $buffer );
95 }
96  
97 sub chain_loc {
98 3933 ▶ my $self = shift;
Subroutine chain_loc: called CC=1 SCAR=0.0
Pod undocumented
99 return unpack(
100 3933 $StP{$self->engine->byte_size},
101 $self->engine->storage->read_at(
102 $self->offset + $self->base_size,
103 $self->engine->byte_size,
104 ),
105 );
106 }
107  
108 sub data {
109 1137 ▶ my $self = shift;
Subroutine data: called CC=2 SCAR=6.9
Pod undocumented
110  
111 1137 my $data;
112 1137 while ( 1 ) {
113 3578 my $chain_loc = $self->chain_loc;
114  
115 3578 $data .= $self->engine->storage->read_at(
116 $self->offset + $self->base_size + $self->engine->byte_size + 1, $self->data_length,
117 );
118  
119 3578 ▶ last unless $chain_loc;
Branch: 1 branch
BranchTrueFalseTotal
unless $chain_loc 1137 2441 3578
120  
121 2441 $self = $self->engine->load_sector( $chain_loc );
122 }
123  
124 1137 return $data;
125 }
126  
127 47 1;
128 __END__
« blib/lib/DBM/Deep.pm ↑ Summary blib/lib/DBM/Deep/Iterator/File/BucketList.pm »