##
# Setup constants for users to pass to new()
##
-sub TYPE_HASH () { DBM::Deep::Engine::SIG_HASH }
-sub TYPE_ARRAY () { DBM::Deep::Engine::SIG_ARRAY }
-sub TYPE_SCALAR () { DBM::Deep::Engine::SIG_SCALAR }
+sub TYPE_HASH () { DBM::Deep::Engine->SIG_HASH }
+sub TYPE_ARRAY () { DBM::Deep::Engine->SIG_ARRAY }
sub _get_args {
my $proto = shift;
# Setup $self and bless into this class.
##
my $class = shift;
- my $args = shift;
+ my ($args) = @_;
# These are the defaults to be optionally overridden below
my $self = bless {
type => TYPE_HASH,
engine => DBM::Deep::Engine->new,
+ base_offset => undef,
}, $class;
- $self->{base_offset} = length( $self->{engine}->SIG_FILE );
-
foreach my $param ( keys %$self ) {
next unless exists $args->{$param};
$self->{$param} = delete $args->{$param}
# times before unlock(), then the same number of unlocks() must
# be called before the lock is released.
##
- my $self = $_[0]->_get_self;
- my $type = $_[1];
+ my $self = shift->_get_self;
+ my ($type) = @_;
$type = LOCK_EX unless defined $type;
if (!defined($self->_fh)) { return; }
# If db locking is set, unlock the db file. See note in lock()
# regarding calling lock() multiple times.
##
- my $self = $_[0]->_get_self;
+ my $self = shift->_get_self;
if (!defined($self->_fh)) { return; }
##
# Recursively export into standard Perl hashes and arrays.
##
- my $self = $_[0]->_get_self;
+ my $self = shift->_get_self;
my $temp;
if ($self->_type eq TYPE_HASH) { $temp = {}; }
##
# Recursively import Perl hash/array structure
##
- #XXX This use of ref() seems to be ok
if (!ref($_[0])) { return; } # Perl calls import() on use -- ignore
- my $self = $_[0]->_get_self;
- my $struct = $_[1];
+ my $self = shift->_get_self;
+ my ($struct) = @_;
- #XXX This use of ref() seems to be ok
+ # struct is not a reference, so just import based on our type
if (!ref($struct)) {
- ##
- # struct is not a reference, so just import based on our type
- ##
- shift @_;
-
if ($self->_type eq TYPE_HASH) { $struct = {@_}; }
elsif ($self->_type eq TYPE_ARRAY) { $struct = [@_]; }
}
# Rebuild entire database into new file, then move
# it back on top of original.
##
- my $self = $_[0]->_get_self;
+ my $self = shift->_get_self;
#XXX Need to create a new test for this
# if ($self->_root->{links} > 1) {
file => $self->_root->{file} . '.tmp',
type => $self->_type
);
- if (!$db_temp) {
- $self->_throw_error("Cannot optimize: failed to open temp file: $!");
- }
$self->lock();
$self->_copy_node( $db_temp );
##
# Make copy of object and return
##
- my $self = $_[0]->_get_self;
+ my $self = shift->_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;
- my $type = lc $_[1];
- my $func = $_[2] ? $_[2] : undef;
+ my $self = shift->_get_self;
+ my $type = lc shift;
+ my $func = shift;
if ( $is_legal_filter{$type} ) {
$self->_root->{"filter_$type"} = $func;
return $self->{root};
}
-sub _fh {
- ##
- # Get access to the raw fh
- ##
- my $self = $_[0]->_get_self;
- return $self->_root->{fh};
-}
-
sub _type {
##
# Get type of current node (TYPE_HASH or TYPE_ARRAY)
return $self->{base_offset};
}
+sub _fh {
+ ##
+ # Get access to the raw fh
+ ##
+ my $self = $_[0]->_get_self;
+ return $self->_root->{fh};
+}
+
##
# Utility methods
##
# Fetch single value or element given plain key or array index
##
my $self = shift->_get_self;
- my $key = shift;
+ my ($key) = @_;
my $md5 = $self->{engine}{digest}->($key);
}
1;
-
__END__
=head1 NAME
the execution path, and Perl indeed passes an empty hash to the STORE() method.
Probably a bug in Perl.
+=head2 REFERENCES
+
+(The reasons given assume a high level of Perl understanding, specifically of
+references. You can safely skip this section.)
+
+Currently, the only references supported are HASH and ARRAY. The other reference
+types (SCALAR, CODE, GLOB, and REF) cannot be supported for various reasons.
+
+=over 4
+
+=item * GLOB
+
+These are things like filehandles and other sockets. They can't be supported
+because it's completely unclear how DBM::Deep should serialize them.
+
+=item * SCALAR / REF
+
+The discussion here refers to the following type of example:
+
+ my $x = 25;
+ $db->{key1} = \$x;
+
+ $x = 50;
+
+ # In some other process ...
+
+ my $val = ${ $db->{key1} };
+
+ is( $val, 50, "What actually gets stored in the DB file?" );
+
+The problem is one of synchronization. When the variable being referred to
+changes value, the reference isn't notified. This means that the new value won't
+be stored in the datafile for other processes to read. There is no TIEREF.
+
+It is theoretically possible to store references to values already within a
+DBM::Deep object because everything already is synchronized, but the change to
+the internals would be quite large. Specifically, DBM::Deep would have to tie
+every single value that is stored. This would bloat the RAM footprint of
+DBM::Deep at least twofold (if not more) and be a significant performance drain,
+all to support a feature that has never been requested.
+
+=item * CODE
+
+L<http://search.cpan.org/search?module=Data::Dump::Streamer> provides a
+mechanism for serializing coderefs, including saving off all closure state.
+However, just as for SCALAR and REF, that closure state may change without
+notifying the DBM::Deep object storing the reference.
+
+=back
+
=head2 FILE CORRUPTION
The current level of error handling in DBM::Deep is minimal. Files I<are> checked