sub FETCH {
my $self = shift->_get_self;
+ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_storage->{filter_store_key})
? $self->_storage->{filter_store_key}->($_[0])
: $_[0];
sub STORE {
my $self = shift->_get_self;
+ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_storage->{filter_store_key})
? $self->_storage->{filter_store_key}->($_[0])
: $_[0];
sub EXISTS {
my $self = shift->_get_self;
+ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_storage->{filter_store_key})
? $self->_storage->{filter_store_key}->($_[0])
: $_[0];
sub DELETE {
my $self = shift->_get_self;
+ DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_storage->{filter_store_key})
? $self->_storage->{filter_store_key}->($_[0])
: $_[0];
# DBM::Deep Test
##
use strict;
-use Test::More tests => 41;
+use Test::More tests => 49;
use Test::Exception;
use t::common qw( new_fh );
$db->{unknown}{bar} = 1;
ok( $db->{unknown}, 'Autovivified hash exists' );
cmp_ok( $db->{unknown}{bar}, '==', 1, 'And the value stored is there' );
+
+# Test failures
+throws_ok {
+ $db->fetch();
+} qr/Cannot use an undefined hash key/, "FETCH fails on an undefined key";
+
+throws_ok {
+ $db->fetch(undef);
+} qr/Cannot use an undefined hash key/, "FETCH fails on an undefined key";
+
+throws_ok {
+ $db->store();
+} qr/Cannot use an undefined hash key/, "STORE fails on an undefined key";
+
+throws_ok {
+ $db->store(undef, undef);
+} qr/Cannot use an undefined hash key/, "STORE fails on an undefined key";
+
+throws_ok {
+ $db->delete();
+} qr/Cannot use an undefined hash key/, "DELETE fails on an undefined key";
+
+throws_ok {
+ $db->delete(undef);
+} qr/Cannot use an undefined hash key/, "DELETE fails on an undefined key";
+
+throws_ok {
+ $db->exists();
+} qr/Cannot use an undefined hash key/, "EXISTS fails on an undefined key";
+
+throws_ok {
+ $db->exists(undef);
+} qr/Cannot use an undefined hash key/, "EXISTS fails on an undefined key";
+
throws_ok {
$db->store();
-} qr/Cannot use an undefined array index/, "FETCH fails on an undefined key";
+} qr/Cannot use an undefined array index/, "STORE fails on an undefined key";
throws_ok {
$db->delete( 'foo' );
-} qr/Cannot use 'foo' as an array index/, "STORE fails on an illegal key";
+} qr/Cannot use 'foo' as an array index/, "DELETE fails on an illegal key";
throws_ok {
$db->delete();
-} qr/Cannot use an undefined array index/, "FETCH fails on an undefined key";
+} qr/Cannot use an undefined array index/, "DELETE fails on an undefined key";
throws_ok {
$db->exists( 'foo' );
-} qr/Cannot use 'foo' as an array index/, "STORE fails on an illegal key";
+} qr/Cannot use 'foo' as an array index/, "EXISTS fails on an illegal key";
throws_ok {
$db->exists();
-} qr/Cannot use an undefined array index/, "FETCH fails on an undefined key";
+} qr/Cannot use an undefined array index/, "EXISTS fails on an undefined key";
For some reason, $c doesn't seem to be undefinable in _copy_value. Maybe this
means that the bless()ing should occur iff C<!$c-E<gt>isa('DBM::Deep')>?
-=item * OO Array access with illegal keys
-
-There's a ton of tests that can be written here to verify the gatekeepers in
-the array methods.
-
=item * Splice
=over 4