1 package DBM::Deep::Hash;
6 use warnings FATAL => 'all';
7 no warnings 'recursion';
12 eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
15 sub _repr { return {} }
19 my $args = $class->_get_args( @_ );
21 $args->{type} = $class->TYPE_HASH;
23 return $class->_init($args);
27 my $self = shift->_get_self;
28 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
29 my $key = ($self->_engine->storage->{filter_store_key})
30 ? $self->_engine->storage->{filter_store_key}->($_[0])
33 return $self->SUPER::FETCH( $key, $_[0] );
37 my $self = shift->_get_self;
38 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
39 my $key = ($self->_engine->storage->{filter_store_key})
40 ? $self->_engine->storage->{filter_store_key}->($_[0])
44 return $self->SUPER::STORE( $key, $value, $_[0] );
48 my $self = shift->_get_self;
49 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
50 my $key = ($self->_engine->storage->{filter_store_key})
51 ? $self->_engine->storage->{filter_store_key}->($_[0])
54 return $self->SUPER::EXISTS( $key );
58 my $self = shift->_get_self;
59 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
60 my $key = ($self->_engine->storage->{filter_store_key})
61 ? $self->_engine->storage->{filter_store_key}->($_[0])
64 return $self->SUPER::DELETE( $key, $_[0] );
67 # Locate and return first key (in no particular order)
69 my $self = shift->_get_self;
73 my $result = $self->_engine->get_next_key( $self );
77 return ($result && $self->_engine->storage->{filter_fetch_key})
78 ? $self->_engine->storage->{filter_fetch_key}->($result)
82 # Return next key (in no particular order), given previous one
84 my $self = shift->_get_self;
86 my $prev_key = ($self->_engine->storage->{filter_store_key})
87 ? $self->_engine->storage->{filter_store_key}->($_[0])
92 my $result = $self->_engine->get_next_key( $self, $prev_key );
96 return ($result && $self->_engine->storage->{filter_fetch_key})
97 ? $self->_engine->storage->{filter_fetch_key}->($result)
101 sub first_key { (shift)->FIRSTKEY(@_) }
102 sub next_key { (shift)->NEXTKEY(@_) }
107 while ( defined(my $key = $self->first_key) ) {
109 $self->_engine->delete_key( $self, $key, $key );
110 } while defined($key = $self->next_key($key));
120 my $key = $self->first_key();
121 while (defined $key) {
122 my $value = $self->get($key);
123 $self->_copy_value( \$db_temp->{$key}, $value );
124 $key = $self->next_key($key);