sub TYPE_HASH () { return SIG_HASH; }
sub TYPE_ARRAY () { return SIG_ARRAY; }
-sub _get_self { $_[0] }
sub new {
##
# Class constructor method for Perl OO interface.
my $class = shift;
my $args = shift;
+ # These are the defaults to be optionally overridden below
my $self = {
type => TYPE_HASH,
base_offset => length(SIG_FILE),
# Open a FileHandle to the database, create if nonexistent.
# Make sure file signature matches DeepDB spec.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
if (defined($self->fh)) { $self->_close(); }
##
# Close database FileHandle
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
close $self->root->{fh};
}
##
# Locate next key, given digested previous one
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
$self->{prev_md5} = $_[1] ? $_[1] : undef;
$self->{return_next} = 0;
# times before unlock(), then the same number of unlocks() must
# be called before the lock is released.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $type = $_[1];
$type = LOCK_EX unless defined $type;
# If db locking is set, unlock the db file. See note in lock()
# regarding calling lock() multiple times.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
if ($self->root->{locking} && $self->root->{locked} > 0) {
$self->root->{locked}--;
# Copy single level of keys or elements to new DB handle.
# Recurse for nested structures
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $db_temp = $_[1];
if ($self->type eq TYPE_HASH) {
##
# Recursively export into standard Perl hashes and arrays.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $temp;
if ($self->type eq TYPE_HASH) { $temp = {}; }
#XXX This use of ref() seems to be ok
if (!ref($_[0])) { return; } # Perl calls import() on use -- ignore
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $struct = $_[1];
#XXX This use of ref() seems to be ok
# Rebuild entire database into new file, then move
# it back on top of original.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
#XXX Need to create a new test for this
# if ($self->root->{links} > 1) {
##
# Make copy of object and return
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
return DBM::Deep->new(
type => $self->type,
##
# Setup filter function for storing or fetching the key or value
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $type = lc $_[1];
my $func = $_[2] ? $_[2] : undef;
##
# Get access to the root structure
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
return $self->{root};
}
# Get access to the raw FileHandle
##
#XXX It will be useful, though, when we split out HASH and ARRAY
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
return $self->root->{fh};
}
##
# Get type of current node (TYPE_HASH or TYPE_ARRAY)
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
return $self->{type};
}
##
# Get base_offset of current node (TYPE_HASH or TYPE_ARRAY)
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
return $self->{base_offset};
}
##
# Store error string in self
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $error_text = $_[1];
$self->root->{error} = $error_text;
##
# Clear error state
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
undef $self->root->{error};
}
##
# Store single hash key/value or array element in database.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $key = ($self->root->{filter_store_key} && $self->type eq TYPE_HASH) ? $self->root->{filter_store_key}->($_[1]) : $_[1];
#XXX What is ref() checking here?
#YYY User may be storing a hash, in which case we do not want it run
##
# Fetch single value or element given plain key or array index
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $key = $_[1];
if ( $self->type eq TYPE_HASH ) {
##
# Delete single key/value pair or element given plain key or array index
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $key = ($self->root->{filter_store_key} && $self->type eq TYPE_HASH) ? $self->root->{filter_store_key}->($_[1]) : $_[1];
my $unpacked_key = $key;
##
# Check if a single key or element exists given plain key or array index
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $key = ($self->root->{filter_store_key} && $self->type eq TYPE_HASH) ? $self->root->{filter_store_key}->($_[1]) : $_[1];
if (($self->type eq TYPE_ARRAY) && ($key =~ /^\d+$/)) { $key = pack($LONG_PACK, $key); }
##
# Clear all keys from hash, or all elements from array.
##
- my $self = $_[0]->_get_self;#_get_self($_[0]);
+ my $self = $_[0]->_get_self;
##
# Make sure file is open
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
- blib/lib/DBM/Deep.pm 94.1 82.9 74.5 98.0 10.5 98.1 88.2
- blib/lib/DBM/Deep/Array.pm 97.8 83.3 50.0 100.0 n/a 1.6 94.4
- blib/lib/DBM/Deep/Hash.pm 93.3 85.7 100.0 100.0 n/a 0.3 92.7
- Total 94.5 83.1 75.5 98.4 10.5 100.0 89.0
+ blib/lib/DBM/Deep.pm 93.9 82.4 74.7 97.9 10.5 85.7 88.0
+ blib/lib/DBM/Deep/Array.pm 97.8 84.6 50.0 100.0 n/a 9.0 94.6
+ blib/lib/DBM/Deep/Hash.pm 93.9 87.5 100.0 100.0 n/a 5.3 93.4
+ Total 94.4 82.9 75.8 98.5 10.5 100.0 89.0
---------------------------- ------ ------ ------ ------ ------ ------ ------
=head1 AUTHOR
##
# Return the length of the array
##
- my $self = $_[0]->_get_self;#DBM::Deep::_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $SAVE_FILTER = $self->root->{filter_fetch_value};
$self->root->{filter_fetch_value} = undef;
##
# Set the length of the array
##
- my $self = $_[0]->_get_self;#DBM::Deep::_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $new_length = $_[1];
my $SAVE_FILTER = $self->root->{filter_store_value};
##
# Remove and return the last element on the array
##
- my $self = $_[0]->_get_self;#DBM::Deep::_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $length = $self->FETCHSIZE();
if ($length) {
##
# Add new element(s) to the end of the array
##
- my $self = (shift(@_))->_get_self;#DBM::Deep::_get_self(shift);
+ my $self = shift->_get_self;
my $length = $self->FETCHSIZE();
while (my $content = shift @_) {
# Remove and return first element on the array.
# Shift over remaining elements to take up space.
##
- my $self = $_[0]->_get_self;#DBM::Deep::_get_self($_[0]);
+ my $self = $_[0]->_get_self;
my $length = $self->FETCHSIZE();
if ($length) {
# Insert new element(s) at beginning of array.
# Shift over other elements to make space.
##
- my $self = $_[0]->_get_self;shift;#DBM::Deep::_get_self($_[0]);shift @_;
+ my $self = shift->_get_self;
my @new_elements = @_;
my $length = $self->FETCHSIZE();
my $new_size = scalar @new_elements;
# Splices section of array with optional new section.
# Returns deleted section, or last element deleted in scalar context.
##
- my $self = $_[0]->_get_self;shift;#DBM::Deep::_get_self($_[0]);shift @_;
+ my $self = shift->_get_self;
my $length = $self->FETCHSIZE();
##