From: rkinyon Date: Fri, 1 Dec 2006 02:11:40 +0000 (+0000) Subject: Added autovivification at the leaf level X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4056dff7df317192c11eab019729c64e2f0fc71e;p=dbsrgits%2FDBM-Deep.git Added autovivification at the leaf level --- diff --git a/lib/DBM/Deep/Engine3.pm b/lib/DBM/Deep/Engine3.pm index 933075c..6013ce4 100644 --- a/lib/DBM/Deep/Engine3.pm +++ b/lib/DBM/Deep/Engine3.pm @@ -115,7 +115,15 @@ sub read_value { }) or die "How did this fail (no blist)?!\n"; my $value_sector = $blist->get_data_for( $key_md5 ); - return if ! $value_sector; + if ( !$value_sector ) { + # Autovivification + $value_sector = DBM::Deep::Engine::Sector::Null->new({ + engine => $self, + data => undef, + }); + + $blist->write_md5( $key_md5, $key, $value_sector->offset ); + } return $value_sector->data; } diff --git a/t/02_hash.t b/t/02_hash.t index d91df74..89a421b 100644 --- a/t/02_hash.t +++ b/t/02_hash.t @@ -39,10 +39,7 @@ ok( exists $db->{key2}, "exists() works against tied hash" ); ok( !exists $db->{key4}, "exists() function works for keys that aren't there" ); is( $db->{key4}, undef, "Autovivified key4" ); -TODO: { - local $TODO = "Autovivification isn't correct yet"; - ok( exists $db->{key4}, "Autovivified key4 now exists" ); -} +ok( exists $db->{key4}, "Autovivified key4 now exists" ); delete $db->{key4}; ok( !exists $db->{key4}, "And key4 doesn't exists anymore" );