1 package DBM::Deep::Hash;
8 our $VERSION = q(1.0006);
13 eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
16 sub _repr { return {} }
20 # Tied hash constructor method, called by Perl's tie() function.
23 my $args = $class->_get_args( @_ );
25 $args->{type} = $class->TYPE_HASH;
27 return $class->_init($args);
31 my $self = shift->_get_self;
32 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
33 my $key = ($self->_storage->{filter_store_key})
34 ? $self->_storage->{filter_store_key}->($_[0])
37 return $self->SUPER::FETCH( $key, $_[0] );
41 my $self = shift->_get_self;
42 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
43 my $key = ($self->_storage->{filter_store_key})
44 ? $self->_storage->{filter_store_key}->($_[0])
48 return $self->SUPER::STORE( $key, $value, $_[0] );
52 my $self = shift->_get_self;
53 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
54 my $key = ($self->_storage->{filter_store_key})
55 ? $self->_storage->{filter_store_key}->($_[0])
58 return $self->SUPER::EXISTS( $key );
62 my $self = shift->_get_self;
63 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
64 my $key = ($self->_storage->{filter_store_key})
65 ? $self->_storage->{filter_store_key}->($_[0])
68 return $self->SUPER::DELETE( $key, $_[0] );
73 # Locate and return first key (in no particular order)
75 my $self = shift->_get_self;
78 # Request shared lock for reading
80 $self->lock( $self->LOCK_SH );
82 my $result = $self->_engine->get_next_key( $self );
86 return ($result && $self->_storage->{filter_fetch_key})
87 ? $self->_storage->{filter_fetch_key}->($result)
93 # Return next key (in no particular order), given previous one
95 my $self = shift->_get_self;
97 my $prev_key = ($self->_storage->{filter_store_key})
98 ? $self->_storage->{filter_store_key}->($_[0])
102 # Request shared lock for reading
104 $self->lock( $self->LOCK_SH );
106 my $result = $self->_engine->get_next_key( $self, $prev_key );
110 return ($result && $self->_storage->{filter_fetch_key})
111 ? $self->_storage->{filter_fetch_key}->($result)
116 # Public method aliases
118 sub first_key { (shift)->FIRSTKEY(@_) }
119 sub next_key { (shift)->NEXTKEY(@_) }
125 my $key = $self->first_key();
127 my $value = $self->get($key);
128 $self->_copy_value( \$db_temp->{$key}, $value );
129 $key = $self->next_key($key);