| 1 | package DBM::Deep::Sector::File::Reference; | ||||||||||||||||||||||||||||||||||||||||||
| 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 _init { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 9272 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9272 | my $e = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9272 | ▶ | unless ( $self->offset ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 280 | my $classname = Scalar::Util::blessed( delete $self->{data} ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 280 | my $leftover = $self->size - $self->base_size - 3 * $e->byte_size; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 280 | my $class_offset = 0; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 280 | ▶ | if ( defined $classname ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 22 | my $class_sector = DBM::Deep::Sector::File::Scalar->new({ | |||||||||||||||||||||||||||||||||||||||||
| 32 | engine => $e, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | data => $classname, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 22 | $class_offset = $class_sector->offset; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 280 | $self->{offset} = $e->_request_data_sector( $self->size ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 280 | $e->storage->print_at( $self->offset, $self->type ); # Sector type | |||||||||||||||||||||||||||||||||||||||||
| 40 | # Skip staleness counter | ||||||||||||||||||||||||||||||||||||||||||
| 41 | $e->storage->print_at( $self->offset + $self->base_size, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | pack( $StP{$e->byte_size}, 0 ), # Index/BList loc | ||||||||||||||||||||||||||||||||||||||||||
| 43 | pack( $StP{$e->byte_size}, $class_offset ), # Classname loc | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 280 | pack( $StP{$e->byte_size}, 1 ), # Initial refcount | |||||||||||||||||||||||||||||||||||||||||
| 45 | chr(0) x $leftover, # Zero-fill the rest | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 8992 | $self->{type} = $e->storage->read_at( $self->offset, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | $self->{staleness} = unpack( | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 9272 | $StP{$STALE_SIZE}, | |||||||||||||||||||||||||||||||||||||||||
| 54 | $e->storage->read_at( $self->offset + $e->SIG_SIZE, $STALE_SIZE ), | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 9272 | return; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | sub get_data_location_for { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 4205 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_data_location_for: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 4205 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Assume that the head is not allowed unless otherwise specified. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 4205 | ▶ | $args->{allow_head} = 0 unless exists $args->{allow_head}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # Assume we don't create a new blist location unless otherwise specified. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 4205 | ▶ | $args->{create} = 0 unless exists $args->{create}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | my $blist = $self->get_bucket_list({ | ||||||||||||||||||||||||||||||||||||||||||
| 71 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | key => $args->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | create => $args->{create}, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 4205 | }); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 4205 | ▶ | return unless $blist && $blist->{found}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$blist and $blist->{"found"}
MC/DC100%2/2
$blist and $blist->{"found"}
$blist
$blist->{"found"}
Truth table100%3/3
A and B
A= $blistB= $blist->{"found"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # At this point, $blist knows where the md5 is. What it -doesn't- know yet | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # is whether or not this transaction has this key. That's part of the next | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # function call. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | my $location = $blist->get_data_location_for({ | ||||||||||||||||||||||||||||||||||||||||||
| 81 | allow_head => $args->{allow_head}, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 3131 | ▶ | }) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3078 | return $location; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | sub get_data_for { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 3195 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_data_for: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 3195 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 3195 | ▶ | my $location = $self->get_data_location_for( $args ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 3075 | return $self->engine->load_sector( $location ); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | sub write_data { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 1790 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_data: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1790 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | my $blist = $self->get_bucket_list({ | ||||||||||||||||||||||||||||||||||||||||||
| 102 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | key => $args->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 1790 | ▶ | create => 1, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | }) or DBM::Deep->_throw_error( "How did write_data fail (no blist)?!" ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # Handle any transactional bookkeeping. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 1790 | ▶ | if ( $self->engine->trans_id ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 68 | ▶ | if ( ! $blist->has_md5 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 40 | $blist->mark_deleted({ | |||||||||||||||||||||||||||||||||||||||||
| 111 | trans_id => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 1722 | my @trans_ids = $self->engine->get_running_txn_ids; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 1722 | ▶ | if ( $blist->has_md5 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 180 | ▶ | if ( @trans_ids ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | my $old_value = $blist->get_data_for; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | foreach my $other_trans_id ( @trans_ids ) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | next if $blist->get_data_location_for({ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | trans_id => $other_trans_id, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | allow_head => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | $blist->write_md5({ | ||||||||||||||||||||||||||||||||||||||||||
| 126 | trans_id => $other_trans_id, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | key => $args->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 3 | value => $old_value->clone, | |||||||||||||||||||||||||||||||||||||||||
| 130 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 1542 | ▶ | if ( @trans_ids ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | foreach my $other_trans_id ( @trans_ids ) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | #XXX This doesn't seem to possible to ever happen . . . | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | next if $blist->get_data_location_for({ trans_id => $other_trans_id, allow_head => 0 }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | $blist->mark_deleted({ | |||||||||||||||||||||||||||||||||||||||||
| 140 | trans_id => $other_trans_id, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | #XXX Is this safe to do transactionally? | ||||||||||||||||||||||||||||||||||||||||||
| 148 | # Free the place we're about to write to. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 1790 | ▶ | if ( $blist->get_data_location_for({ allow_head => 0 }) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 187 | $blist->get_data_for({ allow_head => 0 })->free; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | $blist->write_md5({ | ||||||||||||||||||||||||||||||||||||||||||
| 154 | key => $args->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | value => $args->{value}, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 1790 | }); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | sub delete_key { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 55 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_key: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 55 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | # This can return nothing if we are deleting an entry in a hashref that was | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # auto-vivified as part of the delete process. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 166 | # my $x = {}; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # delete $x->{foo}{bar}; | ||||||||||||||||||||||||||||||||||||||||||
| 168 | my $blist = $self->get_bucket_list({ | ||||||||||||||||||||||||||||||||||||||||||
| 169 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 55 | ▶ | }) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | # Save the location so that we can free the data | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 54 | my $location = $blist->get_data_location_for({ | |||||||||||||||||||||||||||||||||||||||||
| 174 | allow_head => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 54 | ▶ | my $old_value = $location && $self->engine->load_sector( $location ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$location && $self->engine->load_sector($location)
MC/DC50%1/2
$location && $self->engine->load_sector($location)
$location
$self->engine->load_sector($location)
Truth table66%2/3
A && B
A= $locationB= $self->engine->load_sector($location)
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 54 | my @trans_ids = $self->engine->get_running_txn_ids; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | # If we're the HEAD and there are running txns, then we need to clone this | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # value to the other transactions to preserve Isolation. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 54 | ▶ | if ( $self->engine->trans_id == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 43 | ▶ | if ( @trans_ids ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | foreach my $other_trans_id ( @trans_ids ) { | |||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | next if $blist->get_data_location_for({ trans_id => $other_trans_id, allow_head => 0 }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | $blist->write_md5({ | ||||||||||||||||||||||||||||||||||||||||||
| 187 | trans_id => $other_trans_id, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | key => $args->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 189 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | value => $old_value->clone, | |||||||||||||||||||||||||||||||||||||||||
| 191 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 54 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 54 | ▶ | if ( @trans_ids ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 12 | $blist->mark_deleted( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 12 | ▶ | if ( $old_value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | #XXX Is this export => 1 actually doing anything? | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $data = $old_value->data({ export => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $old_value->free; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 42 | $data = $blist->delete_md5( $args ); | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 54 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | sub write_blist_loc { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 243 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_blist_loc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 243 | my ($loc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 243 | my $engine = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 218 | $engine->storage->print_at( $self->offset + $self->base_size, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 243 | pack( $StP{$engine->byte_size}, $loc ), | |||||||||||||||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | sub get_blist_loc { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 6435 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_blist_loc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 6435 | my $e = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 6435 | my $blist_loc = $e->storage->read_at( $self->offset + $self->base_size, $e->byte_size ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 6435 | return unpack( $StP{$e->byte_size}, $blist_loc ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | sub get_bucket_list { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 6050 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_bucket_list: called CC=21 SCAR=30.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 6050 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 6050 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | # XXX Add in check here for recycling? | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 6050 | my $engine = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 6050 | my $blist_loc = $self->get_blist_loc; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | # There's no index or blist yet | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 6050 | ▶ | unless ( $blist_loc ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 257 | ▶ | return unless $args->{create}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | my $blist = DBM::Deep::Sector::File::BucketList->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 247 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 243 | }); | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 243 | $self->write_blist_loc( $blist->offset ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | # $engine->storage->print_at( $self->offset + $self->base_size, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | # pack( $StP{$engine->byte_size}, $blist->offset ), | ||||||||||||||||||||||||||||||||||||||||||
| 254 | # ); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 243 | return $blist; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 5793 | ▶ | my $sector = $engine->load_sector( $blist_loc ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | or DBM::Deep->_throw_error( "Cannot read sector at $blist_loc in get_bucket_list()" ); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 5793 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 5793 | my $last_sector = undef; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 5793 | ▶ | while ( $sector->isa( 'DBM::Deep::Sector::File::Index' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 4072 | $blist_loc = $sector->get_entry( ord( substr( $args->{key_md5}, $i++, 1 ) ) ); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 4072 | $last_sector = $sector; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 4072 | ▶ | if ( $blist_loc ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 3578 | ▶ | $sector = $engine->load_sector( $blist_loc ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | or DBM::Deep->_throw_error( "Cannot read sector at $blist_loc in get_bucket_list()" ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 494 | $sector = undef; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 494 | last; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | # This means we went through the Index sector(s) and found an empty slot | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 5793 | ▶ | unless ( $sector ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 494 | ▶ | return unless $args->{create}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 255 | ▶ | DBM::Deep->_throw_error( "No last_sector when attempting to build a new entry" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | unless $last_sector; | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | my $blist = DBM::Deep::Sector::File::BucketList->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 284 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 255 | }); | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 255 | $last_sector->set_entry( ord( substr( $args->{key_md5}, $i - 1, 1 ) ) => $blist->offset ); | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 255 | return $blist; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 5299 | $sector->find_md5( $args->{key_md5} ); | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | # See whether or not we need to reindex the bucketlist | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # Yes, the double-braces are there for a reason. if() doesn't create a | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # redo-able block, so we have to create a bare block within the if() for | ||||||||||||||||||||||||||||||||||||||||||
| 298 | # redo-purposes. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | # Patch and idea submitted by sprout@cpan.org. -RobK, 2008-01-09 | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 5299 | ▶ | if ( !$sector->has_md5 && $args->{create} && $sector->{idx} == -1 ) {{ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $sector->has_md5 and $args->{"create"} and $sector->{"idx"} == -1
not $sector->has_md5 and $args->{"create"}
MC/DC100%3/3
not $sector->has_md5 and $args->{"create"} and $sector->{"idx"} == -1
not $sector->has_md5
$args->{"create"}
$sector->{"idx"} == -1
Truth table100%4/4
not(A) and B and C
A= not $sector->has_md5B= $args->{"create"}C= $sector->{"idx"} == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 7 | my $redo; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 11 | my $new_index = DBM::Deep::Sector::File::Index->new({ | |||||||||||||||||||||||||||||||||||||||||
| 304 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 305 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 11 | my %blist_cache; | |||||||||||||||||||||||||||||||||||||||||
| 308 | #XXX q.v. the comments for this function. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 11 | foreach my $entry ( $sector->chopped_up ) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 176 | my ($spot, $md5) = @{$entry}; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 176 | my $idx = ord( substr( $md5, $i, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | # XXX This is inefficient | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 176 | ▶ | my $blist = $blist_cache{$idx} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$blist_cache{$idx} ||= "DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
MC/DC0%0/2
$blist_cache{$idx} ||= "DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
$blist_cache{$idx}
"DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
Truth table66%2/3
A ||= B
A= $blist_cache{$idx}B= "DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | ||= DBM::Deep::Sector::File::BucketList->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 316 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 317 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 176 | $new_index->set_entry( $idx => $blist->offset ); | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 176 | my $new_spot = $blist->write_at_next_open( $md5 ); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 176 | $engine->reindex_entry( $spot => $new_spot ); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # Handle the new item separately. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 11 | my $idx = ord( substr( $args->{key_md5}, $i, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | # If all the previous blist's items have been thrown into one | ||||||||||||||||||||||||||||||||||||||||||
| 330 | # blist and the new item belongs in there too, we need | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # another index. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 11 | ▶ | if ( keys %blist_cache == 1 and each %blist_cache == $idx ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
keys %blist_cache == 1 and each %blist_cache == $idx
MC/DC50%1/2
keys %blist_cache == 1 and each %blist_cache == $idx
keys %blist_cache == 1
each %blist_cache == $idx
Truth table66%2/3
A and B
A= keys %blist_cache == 1B= each %blist_cache == $idx
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | ++$i, ++$redo; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 7 | ▶ | my $blist = $blist_cache{$idx} | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$blist_cache{$idx} ||= "DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
MC/DC0%0/2
$blist_cache{$idx} ||= "DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
$blist_cache{$idx}
"DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
Truth table66%2/3
A ||= B
A= $blist_cache{$idx}B= "DBM::Deep::Sector::File::BucketList"->new({"engine", $engine})
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | ||= DBM::Deep::Sector::File::BucketList->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 337 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 338 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 7 | $new_index->set_entry( $idx => $blist->offset ); | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | #XXX THIS IS HACKY! | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | $blist->find_md5( $args->{key_md5} ); | |||||||||||||||||||||||||||||||||||||||||
| 344 | $blist->write_md5({ | ||||||||||||||||||||||||||||||||||||||||||
| 345 | key => $args->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 346 | key_md5 => $args->{key_md5}, | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 7 | value => DBM::Deep::Sector::File::Null->new({ | |||||||||||||||||||||||||||||||||||||||||
| 348 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | data => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 350 | }), | ||||||||||||||||||||||||||||||||||||||||||
| 351 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 11 | ▶ | if ( $last_sector ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | $last_sector->set_entry( | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | ord( substr( $args->{key_md5}, $i - 1, 1 ) ), | |||||||||||||||||||||||||||||||||||||||||
| 358 | $new_index->offset, | ||||||||||||||||||||||||||||||||||||||||||
| 359 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | $engine->storage->print_at( $self->offset + $self->base_size, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 7 | pack( $StP{$engine->byte_size}, $new_index->offset ), | |||||||||||||||||||||||||||||||||||||||||
| 363 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 11 | $sector->wipe; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 11 | $sector->free; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 11 | ▶ | if ( $redo ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 4 | (undef, $sector) = %blist_cache; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 4 | $last_sector = $new_index; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 4 | redo; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 7 | $sector = $blist_cache{ ord( substr( $args->{key_md5}, $i, 1 ) ) }; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 7 | $sector->find_md5( $args->{key_md5} ); | |||||||||||||||||||||||||||||||||||||||||
| 377 | }} | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 5299 | return $sector; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | sub get_class_offset { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 2345 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_class_offset: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 2345 | my $e = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 386 | return unpack( | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 2345 | $StP{$e->byte_size}, | |||||||||||||||||||||||||||||||||||||||||
| 388 | $e->storage->read_at( | ||||||||||||||||||||||||||||||||||||||||||
| 389 | $self->offset + $self->base_size + 1 * $e->byte_size, $e->byte_size, | ||||||||||||||||||||||||||||||||||||||||||
| 390 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | sub get_classname { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 2314 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_classname: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 2314 | my $class_offset = $self->get_class_offset; | |||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 2314 | ▶ | return unless $class_offset; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 43 | return $self->engine->load_sector( $class_offset )->data; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | # Look to hoist this method into a ::Reference trait | ||||||||||||||||||||||||||||||||||||||||||
| 405 | sub data { | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 2323 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 2323 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 2323 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 2323 | my $engine = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 411 | # if ( !exists $engine->cache->{ $self->offset }{ $engine->trans_id } ) { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 2323 | my $obj = DBM::Deep->new({ | |||||||||||||||||||||||||||||||||||||||||
| 413 | type => $self->type, | ||||||||||||||||||||||||||||||||||||||||||
| 414 | base_offset => $self->offset, | ||||||||||||||||||||||||||||||||||||||||||
| 415 | staleness => $self->staleness, | ||||||||||||||||||||||||||||||||||||||||||
| 416 | storage => $engine->storage, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | engine => $engine, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | # $engine->cache->{$self->offset}{ $engine->trans_id } = $obj; | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | # my $obj = $engine->cache->{$self->offset}{ $engine->trans_id }; | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | # We're not exporting, so just return. | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 2323 | ▶ | unless ( $args->{export} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 2317 | ▶ | if ( $engine->storage->{autobless} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 2304 | my $classname = $self->get_classname; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 2304 | ▶ | if ( defined $classname ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 39 | bless $obj, $classname; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 2317 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | # We shouldn't export if this is still referred to. | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 6 | ▶ | if ( $self->get_refcount > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 2 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 4 | return $obj->export; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | sub free { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 34 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
free: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | # We're not ready to be removed yet. | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 34 | ▶ | return if $self->decrement_refcount > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 31 | my $e = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | # Rebless the object into DBM::Deep::Null. | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # eval { %{ $e->cache->{ $self->offset }{ $e->trans_id } } = (); }; | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # eval { @{ $e->cache->{ $self->offset }{ $e->trans_id } } = (); }; | ||||||||||||||||||||||||||||||||||||||||||
| 455 | # bless $e->cache->{ $self->offset }{ $e->trans_id }, 'DBM::Deep::Null'; | ||||||||||||||||||||||||||||||||||||||||||
| 456 | # delete $e->cache->{ $self->offset }{ $e->trans_id }; | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 31 | my $blist_loc = $self->get_blist_loc; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 31 | ▶ | $e->load_sector( $blist_loc )->free if $blist_loc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 31 | my $class_loc = $self->get_class_offset; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 31 | ▶ | $e->load_sector( $class_loc )->free if $class_loc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 31 | $self->SUPER::free(); | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | sub increment_refcount { | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 1009 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
increment_refcount: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 1009 | my $refcount = $self->get_refcount; | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 1009 | $refcount++; | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 1009 | $self->write_refcount( $refcount ); | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 1009 | return $refcount; | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | sub decrement_refcount { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 34 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decrement_refcount: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 34 | my $refcount = $self->get_refcount; | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 34 | $refcount--; | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 34 | $self->write_refcount( $refcount ); | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 34 | return $refcount; | |||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | sub get_refcount { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 1051 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_refcount: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 1051 | my $e = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 495 | return unpack( | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 1051 | $StP{$e->byte_size}, | |||||||||||||||||||||||||||||||||||||||||
| 497 | $e->storage->read_at( | ||||||||||||||||||||||||||||||||||||||||||
| 498 | $self->offset + $self->base_size + 2 * $e->byte_size, $e->byte_size, | ||||||||||||||||||||||||||||||||||||||||||
| 499 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 500 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | sub write_refcount { | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 1043 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_refcount: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 1043 | my ($num) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 1043 | my $e = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 508 | $e->storage->print_at( | ||||||||||||||||||||||||||||||||||||||||||
| 509 | $self->offset + $self->base_size + 2 * $e->byte_size, | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 1043 | pack( $StP{$e->byte_size}, $num ), | |||||||||||||||||||||||||||||||||||||||||
| 511 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | sub clear { | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 202 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 202 | ▶ | my $blist_loc = $self->get_blist_loc or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 9 | my $engine = $self->engine; | |||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | # This won't work with autoblessed items. | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 9 | ▶ | if ($engine->get_running_txn_ids) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | # ~~~ Temporary; the code below this block needs to be modified to | ||||||||||||||||||||||||||||||||||||||||||
| 524 | # take transactions into account. | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | $self->data->_get_self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 7 | ▶ | my $sector = $engine->load_sector( $blist_loc ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | or DBM::Deep->_throw_error( | ||||||||||||||||||||||||||||||||||||||||||
| 531 | "Cannot read sector at $blist_loc in clear()" | ||||||||||||||||||||||||||||||||||||||||||
| 532 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | # Set blist offset to 0 | ||||||||||||||||||||||||||||||||||||||||||
| 535 | $engine->storage->print_at( $self->offset + $self->base_size, | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 7 | pack( $StP{$engine->byte_size}, 0 ), | |||||||||||||||||||||||||||||||||||||||||
| 537 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | # Free the blist | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 7 | $sector->free; | |||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 47 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 546 | __END__ | ||||||||||||||||||||||||||||||||||||||||||