| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 50 | |||||||||||
| 51 | 4518 | my $next_offset = 0; | |||||||||
| 52 | |||||||||||
| 53 | 4518 | my ($leftover, $this_len, $chunk); | |||||||||
| 54 | 4518 | ▶ | if ( $dlen > $data_section ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 120 | |||||||||||
| 121 | 2441 | $self = $self->engine->load_sector( $chain_loc ); | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 1137 | return $data; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | 47 | 1; | |||||||||
| 128 | __END__ | ||||||||||