my $engine = $self->engine;
unless ( $self->offset ) {
- my $leftover = $self->size - 4 - 2 * $engine->byte_size;
+ 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;
$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}, 0 ), # Blessedness
- pack( $StP{1}, 0 ), # Classname length
- chr(0) x $leftover, # Zero-fill the data
+ $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
);
return;
});
}
+sub get_classname {
+ my $self = shift;
+
+ my $is_blessed = $self->engine->storage->read_at(
+ $self->offset + 2 + 2 * $self->engine->byte_size, 1,
+ );
+ $is_blessed = unpack ( $StP{1}, $is_blessed );
+
+ return unless $is_blessed;
+
+ 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 );
+}
+
sub data {
my $self = shift;
storage => $self->engine->storage,
});
+ if ( $self->engine->storage->{autobless} ) {
+ my $classname = $self->get_classname;
+ if ( defined $classname ) {
+ bless $new_obj, $classname;
+ }
+ }
+
return $new_obj;
}