use base 'DBM::Deep';
+use Scalar::Util ();
+
sub _get_self {
eval { tied( @{$_[0]} ) } || $_[0]
}
}
$args = {@_};
}
- #XXX This use of ref() is bad and is a bug
- elsif (ref($_[0])) { $args = $_[0]; }
- else { $args = { file => shift }; }
+ elsif ( my $type = Scalar::Util::reftype($_[0]) ) {
+ if ( $type ne 'HASH' ) {
+ $class->_throw_error( "Not a hashref in TIEARRAY" );
+ }
+ $args = $_[0];
+ }
+ else {
+ $args = { file => shift };
+ }
$args->{type} = $class->TYPE_ARRAY;
}
$args = {@_};
}
- #XXX This use of ref() is bad and is a bug
- elsif (ref($_[0])) { $args = $_[0]; }
+ elsif ( my $type = Scalar::Util::reftype($_[0]) ) {
+ if ( $type ne 'HASH' ) {
+ $class->_throw_error( "Not a hashref in TIEHASH" );
+ }
+ $args = $_[0];
+ }
else { $args = { file => shift }; }
$args->{type} = $class->TYPE_HASH;
is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
}
-# These are testing the naive use of ref() within TIEHASH and TIEARRAY.
-# They should be doing (Scalar::Util::reftype($_[0]) eq 'HASH') and then
-# erroring out if it's not.
-TODO: {
- todo_skip( "Naive use of {\@_}", 1 );
- unlink "t/test.db";
- my %hash;
- my $db = tie %hash, 'DBM::Deep', [
- file => 't/test.db',
- ];
-
- if ($db->error()) {
- print "ERROR: " . $db->error();
- ok(0);
- exit(0);
- }
- else { ok(1); }
-}
-
-TODO: {
- todo_skip( "Naive use of {\@_}", 1 );
- unlink "t/test.db";
- my @array;
- my $db = tie @array, 'DBM::Deep', [
- file => 't/test.db',
- ];
+unlink "t/test.db";
+throws_ok {
+ tie my %hash, 'DBM::Deep', [ file => 't/test.db' ];
+} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
- if ($db->error()) {
- print "ERROR: " . $db->error();
- ok(0);
- exit(0);
- }
- else { ok(1); }
-}
+unlink "t/test.db";
+throws_ok {
+ tie my @array, 'DBM::Deep', [ file => 't/test.db' ];
+} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
unlink "t/test.db";
throws_ok {