my $self = shift;
my ($struct) = @_;
- eval {
- local $SIG{'__DIE__'};
- $self->push( @$struct );
- }; if ($@) {
- $self->_throw_error("Cannot import: type mismatch");
- }
+ $self->push( @$struct );
return 1;
}
+
sub TIEARRAY {
my $class = shift;
my $args = $class->_get_args( @_ );
$self->lock( $self->LOCK_SH );
- my $orig_key;
- if ( $key =~ /^-?\d+$/ ) {
+ if ( !defined $key ) {
+ DBM::Deep->_throw_error( "Cannot use an undefined array index." );
+ }
+ elsif ( $key =~ /^-?\d+$/ ) {
if ( $key < 0 ) {
$key += $self->FETCHSIZE;
unless ( $key >= 0 ) {
return;
}
}
- $orig_key = $key;
}
- else {
- $orig_key = undef;
+ elsif ( $key ne 'length' ) {
+ $self->unlock;
+ DBM::Deep->_throw_error( "Cannot use '$key' as an array index." );
}
- my $rv = $self->SUPER::FETCH( $key, $orig_key );
+ my $rv = $self->SUPER::FETCH( $key );
$self->unlock;
my $size;
my $idx_is_numeric;
- if ( $key =~ /^\-?\d+$/ ) {
+ if ( !defined $key ) {
+ DBM::Deep->_throw_error( "Cannot use an undefined array index." );
+ }
+ elsif ( $key =~ /^-?\d+$/ ) {
$idx_is_numeric = 1;
if ( $key < 0 ) {
$size = $self->FETCHSIZE;
$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;
$self->lock( $self->LOCK_SH );
- if ( $key =~ /^\-?\d+$/ ) {
+ if ( !defined $key ) {
+ DBM::Deep->_throw_error( "Cannot use an undefined array index." );
+ }
+ elsif ( $key =~ /^-?\d+$/ ) {
if ( $key < 0 ) {
$key += $self->FETCHSIZE;
unless ( $key >= 0 ) {
}
}
}
+ elsif ( $key ne 'length' ) {
+ $self->unlock;
+ DBM::Deep->_throw_error( "Cannot use '$key' as an array index." );
+ }
my $rv = $self->SUPER::EXISTS( $key );
$self->lock( $self->LOCK_EX );
my $size = $self->FETCHSIZE;
- if ( $key =~ /^-?\d+$/ ) {
+ if ( !defined $key ) {
+ DBM::Deep->_throw_error( "Cannot use an undefined array index." );
+ }
+ elsif ( $key =~ /^-?\d+$/ ) {
if ( $key < 0 ) {
$key += $size;
unless ( $key >= 0 ) {
}
}
}
+ 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 $rv;
}
+# Now that we have a real Reference sector, we should store arrayzize there. However,
+# arraysize needs to be transactionally-aware, so a simple location to store it isn't
+# going to work.
sub FETCHSIZE {
my $self = shift->_get_self;
my $SAVE_FILTER = $self->_storage->{filter_fetch_value};
$self->_storage->{filter_fetch_value} = undef;
- my $packed_size = $self->FETCH('length');
+ my $size = $self->FETCH('length') || 0;
$self->_storage->{filter_fetch_value} = $SAVE_FILTER;
$self->unlock;
- if ($packed_size) {
- return int(unpack($self->_engine->{long_pack}, $packed_size));
- }
-
- return 0;
+ return $size;
}
sub STORESIZE {
my $SAVE_FILTER = $self->_storage->{filter_store_value};
$self->_storage->{filter_store_value} = undef;
- my $result = $self->STORE('length', pack($self->_engine->{long_pack}, $new_length), 'length');
+ my $result = $self->STORE('length', $new_length, 'length');
$self->_storage->{filter_store_value} = $SAVE_FILTER;
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 {
##