sub commit {
my $self = shift->_get_self;
- # At this point, we need to replay the actions taken
- $self->_fileobj->end_transaction;
+ $self->_fileobj->commit_transaction;
return 1;
}
sub _find_parent {
my $self = shift;
- if ( $self->{parent} ) {
- my $base = $self->{parent}->_find_parent();
- if ( $self->{parent}->_type eq TYPE_HASH ) {
- return $base . "\{$self->{parent_key}\}";
+
+ my $base = '';
+ if ( my $parent = $self->{parent} ) {
+ my $child = $self;
+ while ( $parent->{parent} ) {
+ $base = (
+ $parent->_type eq TYPE_HASH
+ ? "\{$child->{parent_key}\}"
+ : "\[$child->{parent_key}\]"
+# "->get('$child->{parent_key}')"
+ ) . $base;
+
+ $child = $parent;
+ $parent = $parent->{parent};
+# last unless $parent;
+ }
+ if ( $base ) {
+ $base = "\$db->get( '$child->{parent_key}' )->" . $base;
+ }
+ else {
+ $base = "\$db->get( '$child->{parent_key}' )";
}
- return $base . "\[$self->{parent_key}\]";
}
- return '$db->';
+# return '$db->' . $base;
+# return '$db' . $base;
+ return $base;
}
sub STORE {
$self->_throw_error( 'Cannot write to a readonly filehandle' );
}
- if ( my $afh = $self->_fileobj->{audit_fh} ) {
- if ( defined $orig_key ) {
- my $lhs = $self->_find_parent;
- if ( $self->_type eq TYPE_HASH ) {
- $lhs .= "\{$orig_key\}";
- }
- else {
- $lhs .= "\[$orig_key\]";
- }
+ if ( defined $orig_key ) {
+ my $rhs;
- my $rhs;
+ my $r = Scalar::Util::reftype( $value ) || '';
+ if ( $r eq 'HASH' ) {
+ $rhs = '{}';
+ }
+ elsif ( $r eq 'ARRAY' ) {
+ $rhs = '[]';
+ }
+ elsif ( defined $value ) {
+ $rhs = "'$value'";
+ }
+ else {
+ $rhs = "undef";
+ }
- my $r = Scalar::Util::reftype( $value ) || '';
- if ( $r eq 'HASH' ) {
- $rhs = '{}';
- }
- elsif ( $r eq 'ARRAY' ) {
- $rhs = '[]';
+ if ( my $c = Scalar::Util::blessed( $value ) ) {
+ $rhs = "bless $rhs, '$c'";
+ }
+
+ my $lhs = $self->_find_parent;
+ if ( $lhs ) {
+ if ( $self->_type eq TYPE_HASH ) {
+ $lhs .= "->\{$orig_key\}";
}
else {
- $rhs = "'$value'";
+ $lhs .= "->\[$orig_key\]";
}
- if ( my $c = Scalar::Util::blessed( $value ) ) {
- $rhs = "bless $rhs, '$c'";
- }
-
- $self->_fileobj->audit( "$lhs = $rhs;" );
-# flock( $afh, LOCK_EX );
-# print( $afh "$lhs = $rhs; # " . localtime(time) . "\n" );
-# flock( $afh, LOCK_UN );
+ $lhs .= "=$rhs;";
}
+ else {
+ $lhs = "\$db->put('$orig_key',$rhs);";
+ }
+
+# $self->_fileobj->audit( "$lhs = $rhs;" );
+# $self->_fileobj->audit( "$lhs $rhs);" );
+ $self->_fileobj->audit($lhs);
}
##
$self->_throw_error( 'Cannot write to a readonly filehandle' );
}
- if ( my $afh = $self->_fileobj->{audit_fh} ) {
- if ( defined $orig_key ) {
- my $lhs = $self->_find_parent;
- if ( $self->_type eq TYPE_HASH ) {
- $lhs .= "\{$orig_key\}";
- }
- else {
- $lhs .= "\[$orig_key]\]";
- }
-
- flock( $afh, LOCK_EX );
- print( $afh "delete $lhs; # " . localtime(time) . "\n" );
- flock( $afh, LOCK_UN );
+ if ( defined $orig_key ) {
+ my $lhs = $self->_find_parent;
+# if ( $self->_type eq TYPE_HASH ) {
+# $lhs .= "\{$orig_key\}";
+# }
+# else {
+# $lhs .= "\[$orig_key]\]";
+# }
+
+# $self->_fileobj->audit( "delete $lhs;" );
+# $self->_fileobj->audit( "$lhs->delete('$orig_key');" );
+ if ( $lhs ) {
+ $self->_fileobj->audit( "delete $lhs;" );
+ }
+ else {
+ $self->_fileobj->audit( "\$db->delete('$orig_key');" );
}
}
$self->_throw_error( 'Cannot write to a readonly filehandle' );
}
- if ( my $afh = $self->_fileobj->{audit_fh} ) {
+ {
my $lhs = $self->_find_parent;
- my $rhs = '()';
if ( $self->_type eq TYPE_HASH ) {
$lhs = '%{' . $lhs . '}';
}
$lhs = '@{' . $lhs . '}';
}
- flock( $afh, LOCK_EX );
- print( $afh "$lhs = $rhs; # " . localtime(time) . "\n" );
- flock( $afh, LOCK_UN );
+ $self->_fileobj->audit( "$lhs = ();" );
}
##
##
$self->lock( LOCK_EX );
- my $fh = $self->_fh;
-
- seek($fh, $self->_base_offset + $self->_fileobj->{file_offset}, SEEK_SET);
- if (eof $fh) {
- $self->unlock();
- return;
- }
-
#XXX This needs updating to use _release_space
$self->{engine}->write_tag(
$self->_base_offset, $self->_type,