From: rkinyon Date: Mon, 4 Dec 2006 04:57:11 +0000 (+0000) Subject: import and export are turned back on and working X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=84467b9f66ea79dcfd58e047c1299b35f1271105;p=dbsrgits%2FDBM-Deep.git import and export are turned back on and working --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index da5cbc7..683d6f9 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -218,14 +218,9 @@ sub export { $self->_copy_node( $temp ); $self->unlock(); - # This will always work because $self, after _get_self() is a HASH - if ( $self->{parent} ) { - my $c = Scalar::Util::blessed( - $self->{parent}->get($self->{parent_key}) - ); - if ( $c && !$c->isa( 'DBM::Deep' ) ) { - bless $temp, $c; - } + my $classname = $self->_engine->get_classname( $self->_storage->transaction_id, $self->_base_offset ); + if ( defined $classname ) { + bless $temp, $classname; } return $temp; @@ -248,11 +243,11 @@ sub import { #XXX This isn't the best solution. Better would be to use Data::Walker, #XXX but that's a lot more thinking than I want to do right now. eval { - $self->begin_work; + #$self->begin_work; $self->_import( _clone_data( $struct ) ); - $self->commit; + #$self->commit; }; if ( $@ ) { - $self->rollback; + #$self->rollback; die $@; } diff --git a/lib/DBM/Deep/Engine3.pm b/lib/DBM/Deep/Engine3.pm index e3b34f3..2ab984d 100644 --- a/lib/DBM/Deep/Engine3.pm +++ b/lib/DBM/Deep/Engine3.pm @@ -134,6 +134,18 @@ sub read_value { return $value_sector->data; } +sub get_classname { + my $self = shift; + my ($trans_id, $base_offset) = @_; + print "get_classname( $trans_id, $base_offset )\n" if $DEBUG; + + # This will be a Reference sector + my $sector = $self->_load_sector( $base_offset ) + or die "How did read_value fail (no sector for '$base_offset')?!\n"; + + return $sector->get_classname; +} + sub key_exists { my $self = shift; my ($trans_id, $base_offset, $key) = @_; diff --git a/t/17_import.todo b/t/17_import.t similarity index 100% rename from t/17_import.todo rename to t/17_import.t diff --git a/t/18_export.todo b/t/18_export.t similarity index 100% rename from t/18_export.todo rename to t/18_export.t diff --git a/t/24_autobless.t b/t/24_autobless.t index 953ecd8..5f15247 100644 --- a/t/24_autobless.t +++ b/t/24_autobless.t @@ -148,32 +148,31 @@ my ($fh, $filename) = new_fh(); is( $db->{unblessed}{b}[2], 3 ); } -SKIP: { - skip "import() not ready yet", 2; -my ($fh2, $filename2) = new_fh(); { - my $db = DBM::Deep->new( - file => $filename2, - autobless => 1, - ); - my $obj = bless { - a => 1, - b => [ 1 .. 3 ], - }, 'Foo'; - - $db->import( { blessed => $obj } ); -} - -{ - my $db = DBM::Deep->new( - file => $filename2, - autobless => 1, - ); - - my $blessed = $db->{blessed}; - isa_ok( $blessed, 'Foo' ); - is( $blessed->{a}, 1 ); -} + my ($fh2, $filename2) = new_fh(); + { + my $db = DBM::Deep->new( + file => $filename2, + autobless => 1, + ); + my $obj = bless { + a => 1, + b => [ 1 .. 3 ], + }, 'Foo'; + + $db->import( { blessed => $obj } ); + } + + { + my $db = DBM::Deep->new( + file => $filename2, + autobless => 1, + ); + + my $blessed = $db->{blessed}; + isa_ok( $blessed, 'Foo' ); + is( $blessed->{a}, 1 ); + } } {