/usr/share/perl5/DBM/Deep/Hash.pm is in libdbm-deep-perl 2.0002-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | package DBM::Deep::Hash;
use 5.008_004;
use strict;
use warnings FATAL => 'all';
no warnings 'recursion';
use base 'DBM::Deep';
sub _get_self {
# See the note in Array.pm as to why this is commented out.
# eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
# During global destruction %{$_[0]} might get tied to undef, so we
# need to check that case if tied returns false.
tied %{$_[0]} or local *@, eval { exists $_[0]{_}; 1 } ? $_[0] : undef
}
sub _repr { return {} }
sub TIEHASH {
my $class = shift;
my $args = $class->_get_args( @_ );
$args->{type} = $class->TYPE_HASH;
return $class->_init($args);
}
sub FETCH {
my $self = shift->_get_self;
DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_engine->storage->{filter_store_key})
? $self->_engine->storage->{filter_store_key}->($_[0])
: $_[0];
return $self->SUPER::FETCH( $key, $_[0] );
}
sub STORE {
my $self = shift->_get_self;
DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_engine->storage->{filter_store_key})
? $self->_engine->storage->{filter_store_key}->($_[0])
: $_[0];
my $value = $_[1];
return $self->SUPER::STORE( $key, $value, $_[0] );
}
sub EXISTS {
my $self = shift->_get_self;
DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_engine->storage->{filter_store_key})
? $self->_engine->storage->{filter_store_key}->($_[0])
: $_[0];
return $self->SUPER::EXISTS( $key );
}
sub DELETE {
my $self = shift->_get_self;
DBM::Deep->_throw_error( "Cannot use an undefined hash key." ) unless defined $_[0];
my $key = ($self->_engine->storage->{filter_store_key})
? $self->_engine->storage->{filter_store_key}->($_[0])
: $_[0];
return $self->SUPER::DELETE( $key, $_[0] );
}
# Locate and return first key (in no particular order)
sub FIRSTKEY {
my $self = shift->_get_self;
$self->lock_shared;
my $result = $self->_engine->get_next_key( $self );
$self->unlock;
return ($result && $self->_engine->storage->{filter_fetch_key})
? $self->_engine->storage->{filter_fetch_key}->($result)
: $result;
}
# Return next key (in no particular order), given previous one
sub NEXTKEY {
my $self = shift->_get_self;
my $prev_key = ($self->_engine->storage->{filter_store_key})
? $self->_engine->storage->{filter_store_key}->($_[0])
: $_[0];
$self->lock_shared;
my $result = $self->_engine->get_next_key( $self, $prev_key );
$self->unlock;
return ($result && $self->_engine->storage->{filter_fetch_key})
? $self->_engine->storage->{filter_fetch_key}->($result)
: $result;
}
sub first_key { (shift)->FIRSTKEY(@_) }
sub next_key { (shift)->NEXTKEY(@_) }
sub _clear {
my $self = shift;
while ( defined(my $key = $self->first_key) ) {
do {
$self->_engine->delete_key( $self, $key, $key );
} while defined($key = $self->next_key($key));
}
return;
}
sub _copy_node {
my $self = shift;
my ($db_temp) = @_;
my $key = $self->first_key();
while (defined $key) {
my $value = $self->get($key);
$self->_copy_value( \$db_temp->{$key}, $value );
$key = $self->next_key($key);
}
return 1;
}
1;
__END__
|