1 package DBM::Deep::Hash;
8 our $VERSION = q(1.0009_01);
13 eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
16 #XXX Need to add a check here for @_ % 2
17 sub _repr { shift;return { @_ } }
23 foreach my $key (keys %$struct) {
24 $self->put($key, $struct->{$key});
32 # Tied hash constructor method, called by Perl's tie() function.
35 my $args = $class->_get_args( @_ );
37 $args->{type} = $class->TYPE_HASH;
39 return $class->_init($args);
43 my $self = shift->_get_self;
44 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
45 my $key = ($self->_storage->{filter_store_key})
46 ? $self->_storage->{filter_store_key}->($_[0])
49 return $self->SUPER::FETCH( $key, $_[0] );
53 my $self = shift->_get_self;
54 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
55 my $key = ($self->_storage->{filter_store_key})
56 ? $self->_storage->{filter_store_key}->($_[0])
60 return $self->SUPER::STORE( $key, $value, $_[0] );
64 my $self = shift->_get_self;
65 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
66 my $key = ($self->_storage->{filter_store_key})
67 ? $self->_storage->{filter_store_key}->($_[0])
70 return $self->SUPER::EXISTS( $key );
74 my $self = shift->_get_self;
75 DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
76 my $key = ($self->_storage->{filter_store_key})
77 ? $self->_storage->{filter_store_key}->($_[0])
80 return $self->SUPER::DELETE( $key, $_[0] );
85 # Locate and return first key (in no particular order)
87 my $self = shift->_get_self;
90 # Request shared lock for reading
92 $self->lock( $self->LOCK_SH );
94 my $result = $self->_engine->get_next_key( $self );
98 return ($result && $self->_storage->{filter_fetch_key})
99 ? $self->_storage->{filter_fetch_key}->($result)
105 # Return next key (in no particular order), given previous one
107 my $self = shift->_get_self;
109 my $prev_key = ($self->_storage->{filter_store_key})
110 ? $self->_storage->{filter_store_key}->($_[0])
114 # Request shared lock for reading
116 $self->lock( $self->LOCK_SH );
118 my $result = $self->_engine->get_next_key( $self, $prev_key );
122 return ($result && $self->_storage->{filter_fetch_key})
123 ? $self->_storage->{filter_fetch_key}->($result)
128 # Public method aliases
130 sub first_key { (shift)->FIRSTKEY(@_) }
131 sub next_key { (shift)->NEXTKEY(@_) }
137 my $key = $self->first_key();
139 my $value = $self->get($key);
140 $self->_copy_value( \$db_temp->{$key}, $value );
141 $key = $self->next_key($key);