unless ( $self->offset ) {
my $classname = Scalar::Util::blessed( delete $self->{data} );
- my $class_len = length( defined $classname ? $classname : '' );
- my $leftover = $self->size - 4 - 2 * $engine->byte_size - $class_len;
+ my $leftover = $self->size - 4 - 2 * $engine->byte_size;
+
+ my $class_offset = 0;
+ if ( defined $classname ) {
+ my $class_sector = DBM::Deep::Engine::Sector::Scalar->new({
+ engine => $self->engine,
+ data => $classname,
+ });
+ $class_offset = $class_sector->offset;
+ }
$self->{offset} = $engine->_request_sector( $self->size );
$engine->storage->print_at( $self->offset,
- $self->type, # Sector type
- pack( $StP{1}, 0 ), # Recycled counter
- pack( $StP{$engine->byte_size}, 0 ), # Chain loc
- pack( $StP{$engine->byte_size}, 0 ), # Index/BList loc
- pack( $StP{1}, (defined($classname) ? 1 : 0) ), # Blessedness
- pack( $StP{1}, $class_len ), # Classname length
- (defined($classname) ? $classname : ''), # Classname
- chr(0) x $leftover, # Zero-fill the rest
+ $self->type, # Sector type
+ pack( $StP{1}, 0 ), # Recycled counter
+ pack( $StP{$engine->byte_size}, 0 ), # Index/BList loc
+ pack( $StP{$engine->byte_size}, $class_offset ), # Classname loc
+ chr(0) x $leftover, # Zero-fill the rest
);
return;
my $self = shift;
my $engine = $self->engine;
- my $blist_loc = $engine->storage->read_at( $self->offset + 2 + $engine->byte_size, $engine->byte_size );
+ my $blist_loc = $engine->storage->read_at( $self->offset + 2, $engine->byte_size );
return unpack( $StP{$engine->byte_size}, $blist_loc );
}
my $blist = DBM::Deep::Engine::Sector::BucketList->new({
engine => $engine,
});
- $engine->storage->print_at( $self->offset + 2 + $engine->byte_size,
+ $engine->storage->print_at( $self->offset + 2,
pack( $StP{$engine->byte_size}, $blist->offset ),
);
return $blist;
sub get_classname {
my $self = shift;
- my $is_blessed = $self->engine->storage->read_at(
- $self->offset + 2 + 2 * $self->engine->byte_size, 1,
+ my $class_offset = $self->engine->storage->read_at(
+ $self->offset + 2 + 1 * $self->engine->byte_size, $self->engine->byte_size,
);
- $is_blessed = unpack ( $StP{1}, $is_blessed );
+ $class_offset = unpack ( $StP{$self->engine->byte_size}, $class_offset );
- return unless $is_blessed;
+ return unless $class_offset;
- my $classname_len = $self->engine->storage->read_at( undef, 1 );
- $classname_len = unpack( $StP{1}, $classname_len );
- return $self->engine->storage->read_at( undef, $classname_len );
+ return $self->engine->_load_sector( $class_offset )->data;
}
sub data {