1 package DBM::Deep::Hash;
8 use constant DEBUG => 0;
10 our $VERSION = q(0.99_03);
15 eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
18 #XXX Need to add a check here for @_ % 2
19 sub _repr { shift;return { @_ } }
26 local $SIG{'__DIE__'};
27 foreach my $key (keys %$struct) {
28 $self->put($key, $struct->{$key});
31 $self->_throw_error("Cannot import: type mismatch");
39 # Tied hash constructor method, called by Perl's tie() function.
42 my $args = $class->_get_args( @_ );
44 $args->{type} = $class->TYPE_HASH;
46 return $class->_init($args);
50 print "FETCH( @_ )\n" if DEBUG;
51 my $self = shift->_get_self;
52 my $key = ($self->_storage->{filter_store_key})
53 ? $self->_storage->{filter_store_key}->($_[0])
56 return $self->SUPER::FETCH( $key, $_[0] );
60 print "STORE( @_ )\n" if DEBUG;
61 my $self = shift->_get_self;
62 my $key = ($self->_storage->{filter_store_key})
63 ? $self->_storage->{filter_store_key}->($_[0])
67 return $self->SUPER::STORE( $key, $value, $_[0] );
71 print "EXISTS( @_ )\n" if DEBUG;
72 my $self = shift->_get_self;
73 my $key = ($self->_storage->{filter_store_key})
74 ? $self->_storage->{filter_store_key}->($_[0])
77 return $self->SUPER::EXISTS( $key );
81 my $self = shift->_get_self;
82 my $key = ($self->_storage->{filter_store_key})
83 ? $self->_storage->{filter_store_key}->($_[0])
86 return $self->SUPER::DELETE( $key, $_[0] );
90 print "FIRSTKEY\n" if DEBUG;
92 # Locate and return first key (in no particular order)
94 my $self = shift->_get_self;
97 # Request shared lock for reading
99 $self->lock( $self->LOCK_SH );
101 my $result = $self->_engine->get_next_key($self->_storage->transaction_id, $self->_base_offset);
105 return ($result && $self->_storage->{filter_fetch_key})
106 ? $self->_storage->{filter_fetch_key}->($result)
111 print "NEXTKEY( @_ )\n" if DEBUG;
113 # Return next key (in no particular order), given previous one
115 my $self = shift->_get_self;
117 my $prev_key = ($self->_storage->{filter_store_key})
118 ? $self->_storage->{filter_store_key}->($_[0])
122 # Request shared lock for reading
124 $self->lock( $self->LOCK_SH );
126 my $result = $self->_engine->get_next_key( $self->_storage->transaction_id, $self->_base_offset, $prev_key );
130 return ($result && $self->_storage->{filter_fetch_key})
131 ? $self->_storage->{filter_fetch_key}->($result)
136 # Public method aliases
138 sub first_key { (shift)->FIRSTKEY(@_) }
139 sub next_key { (shift)->NEXTKEY(@_) }
145 my $key = $self->first_key();
147 my $value = $self->get($key);
148 $self->_copy_value( \$db_temp->{$key}, $value );
149 $key = $self->next_key($key);