return 1;
}
+
sub TIEARRAY {
my $class = shift;
my $args = $class->_get_args( @_ );
}
}
}
- else {
+ elsif ( $key ne 'length' ) {
+ $self->unlock;
+ DBM::Deep->_throw_error( "Cannot use '$key' as an array index." );
}
my $rv = $self->SUPER::FETCH( $key );
$key += $size
}
}
+ elsif ( $key ne 'length' ) {
+ $self->unlock;
+ DBM::Deep->_throw_error( "Cannot use '$key' as an array index." );
+ }
- my $rv = $self->SUPER::STORE( $key, $value, ($key eq 'length' ? undef : $key) );
+ my $rv = $self->SUPER::STORE( $key, $value );
if ( $idx_is_numeric ) {
$size = $self->FETCHSIZE unless defined $size;
}
}
}
+ elsif ( $key ne 'length' ) {
+ $self->unlock;
+ DBM::Deep->_throw_error( "Cannot use '$key' as an array index." );
+ }
my $rv = $self->SUPER::EXISTS( $key );
}
}
}
+ elsif ( $key ne 'length' ) {
+ $self->unlock;
+ DBM::Deep->_throw_error( "Cannot use '$key' as an array index." );
+ }
my $rv = $self->SUPER::DELETE( $key );
if ($rv && $key == $size - 1) {
- $self->STORESIZE( $key, ($key eq 'length' ? undef : $key) );
+ $self->STORESIZE( $key );
}
$self->unlock;
return wantarray ? @old_elements : $old_elements[-1];
}
-# We don't need to define it, yet.
+# We don't need to populate it, yet.
# It will be useful, though, when we split out HASH and ARRAY
sub EXTEND {
##
# DBM::Deep Test
##
use strict;
-use Test::More tests => 108;
+use Test::More tests => 112;
use Test::Exception;
use t::common qw( new_fh );
$db->[1] = { a => 'foo' };
is( $db->[0]->length, 3, "Reuse of same space with array successful" );
is( $db->[1]->fetch('a'), 'foo', "Reuse of same space with hash successful" );
-# Test autovivification
+# Test autovivification
$db->[9999]{bar} = 1;
ok( $db->[9999] );
cmp_ok( $db->[9999]{bar}, '==', 1 );
+
+# Test failures
+throws_ok {
+ $db->fetch( 'foo' );
+} qr/Cannot use 'foo' as an array index/, "FETCH fails on an illegal key";
+
+throws_ok {
+ $db->store( 'foo', 'bar' );
+} qr/Cannot use 'foo' as an array index/, "STORE fails on an illegal key";
+
+throws_ok {
+ $db->delete( 'foo' );
+} qr/Cannot use 'foo' as an array index/, "STORE fails on an illegal key";
+
+throws_ok {
+ $db->exists( 'foo' );
+} qr/Cannot use 'foo' as an array index/, "STORE fails on an illegal key";