1 package DBM::Deep::Hash;
8 eval { tied( %{$_[0]} ) } || $_[0]
13 # Tied hash constructor method, called by Perl's tie() function.
17 if (scalar(@_) > 1) { $args = {@_}; }
18 #XXX This use of ref() is bad and is a bug
19 elsif (ref($_[0])) { $args = $_[0]; }
20 else { $args = { file => shift }; }
22 $args->{type} = $class->TYPE_HASH;
24 return $class->_init($args);
28 my $self = shift->_get_self;
29 my $key = ($self->root->{filter_store_key})
30 ? $self->root->{filter_store_key}->($_[0])
34 return $self->SUPER::STORE( $key, $value );
39 # Locate and return first key (in no particular order)
41 my $self = $_[0]->_get_self;
44 # Make sure file is open
46 if (!defined($self->fh)) { $self->_open(); }
49 # Request shared lock for reading
51 $self->lock( $self->LOCK_SH );
53 my $result = $self->_get_next_key();
57 return ($result && $self->root->{filter_fetch_key})
58 ? $self->root->{filter_fetch_key}->($result)
64 # Return next key (in no particular order), given previous one
66 my $self = $_[0]->_get_self;
68 my $prev_key = ($self->root->{filter_store_key})
69 ? $self->root->{filter_store_key}->($_[1])
72 my $prev_md5 = $DBM::Deep::DIGEST_FUNC->($prev_key);
75 # Make sure file is open
77 if (!defined($self->fh)) { $self->_open(); }
80 # Request shared lock for reading
82 $self->lock( $self->LOCK_SH );
84 my $result = $self->_get_next_key( $prev_md5 );
88 return ($result && $self->root->{filter_fetch_key})
89 ? $self->root->{filter_fetch_key}->($result)
94 # Public method aliases
96 *first_key = *FIRSTKEY;