From: rkinyon Date: Mon, 4 Dec 2006 03:51:13 +0000 (+0000) Subject: Values are now restricted to only legal values (hash and array references that aren... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d49782fe79a5afaf6898d4c56b4f97b2ff101b30;p=dbsrgits%2FDBM-Deep.git Values are now restricted to only legal values (hash and array references that aren't tied) --- diff --git a/lib/DBM/Deep/Engine3.pm b/lib/DBM/Deep/Engine3.pm index 5213030..114066e 100644 --- a/lib/DBM/Deep/Engine3.pm +++ b/lib/DBM/Deep/Engine3.pm @@ -190,12 +190,27 @@ sub write_value { }) or die "How did write_value fail (no blist)?!\n"; my $r = Scalar::Util::reftype( $value ) || ''; - #XXX Throw an error here on illegal values + { + last if $r eq ''; + last if $r eq 'HASH'; + last if $r eq 'ARRAY'; + + DBM::Deep->_throw_error( + "Storage of references of type '$r' is not supported." + ); + } + my ($class, $type); if ( !defined $value ) { $class = 'DBM::Deep::Engine::Sector::Null'; } elsif ( $r eq 'ARRAY' || $r eq 'HASH' ) { + if ( $r eq 'ARRAY' && tied(@$value) ) { + DBM::Deep->_throw_error( "Cannot store something that is tied" ); + } + if ( $r eq 'HASH' && tied(%$value) ) { + DBM::Deep->_throw_error( "Cannot store something that is tied" ); + } $class = 'DBM::Deep::Engine::Sector::Reference'; $type = substr( $r, 0, 1 ); } diff --git a/t/26_scalar_ref.todo b/t/26_scalar_ref.t similarity index 100% rename from t/26_scalar_ref.todo rename to t/26_scalar_ref.t diff --git a/t/30_already_tied.todo b/t/30_already_tied.t similarity index 100% rename from t/30_already_tied.todo rename to t/30_already_tied.t diff --git a/t/31_references.t b/t/31_references.t index da588b2..6d91aef 100644 --- a/t/31_references.t +++ b/t/31_references.t @@ -55,6 +55,9 @@ is( $db->{array}[2]{b}, 'floober' ); my %hash2 = ( abc => [ 1 .. 3 ] ); $array[3] = \%hash2; -$hash2{ def } = \%hash; +SKIP: { + skip "Internal references are currently unsupported", 1; + $hash2{ def } = \%hash; -is( $array[3]{def}{foo}, 2 ); + is( $array[3]{def}{foo}, 2 ); +}