use Scalar::Util ();
use vars qw( $VERSION );
-$VERSION = q(0.981_01);
+$VERSION = q(0.981);
##
# Set to 4 and 'N' for 32-bit offset tags (default). Theoretical limit of 4 GB per file.
# These are the defaults to be optionally overridden below
my $self = bless {
- type => TYPE_HASH,
- parent => undef,
- parent_key => undef,
+ type => TYPE_HASH,
base_offset => length(SIG_FILE),
}, $class;
# File is empty -- write signature and master index
##
if (!$bytes_read) {
- if ( my $afh = $self->_root->{audit_fh} ) {
- flock( $afh, LOCK_EX );
- print( $afh "# Database created on " . localtime(time) . $/ );
- flock( $afh, LOCK_UN );
- }
-
seek($fh, 0 + $self->_root->{file_offset}, SEEK_SET);
print( $fh SIG_FILE);
$self->_create_tag($self->_base_offset, $self->_type, chr(0) x $INDEX_SIZE);
# plain (undigested) key and value.
##
my $self = shift;
- my ($tag, $md5, $plain_key, $value, $orig_key) = @_;
+ my ($tag, $md5, $plain_key, $value) = @_;
my $keys = $tag->{content};
my $location = 0;
my $result = 2;
type => TYPE_HASH,
base_offset => $location,
root => $root,
- parent => $self,
- parent_key => $orig_key,
);
foreach my $key (keys %{$value}) {
$branch->STORE( $key, $value->{$key} );
type => TYPE_ARRAY,
base_offset => $location,
root => $root,
- parent => $self,
- parent_key => $orig_key,
);
my $index = 0;
foreach my $element (@{$value}) {
# Fetch single value given tag and MD5 digested key.
##
my $self = shift;
- my ($tag, $md5, $plain_key) = @_;
+ my ($tag, $md5) = @_;
my $keys = $tag->{content};
my $fh = $self->_fh;
if (!$subloc) {
##
# Hit end of list, no match
- ## return;
+ ##
+ return;
}
if ( $md5 ne $key ) {
my $obj = DBM::Deep->new(
type => $signature,
base_offset => $subloc,
- root => $self->_root,
- parent => $self,
- parent_key => $plain_key,
+ root => $self->_root
);
if ($self->_root->{autobless}) {
return DBM::Deep->new(
type => $self->_type,
base_offset => $self->_base_offset,
- root => $self->_root,
- parent => $self->{parent},
- parent_key => $self->{parent_key},
+ root => $self->_root
);
}
# tie() methods (hashes and arrays)
##
-sub _find_parent {
- my $self = shift;
- if ( $self->{parent} ) {
- my $base = $self->{parent}->_find_parent();
- if ( $self->{parent}->_type eq TYPE_HASH ) {
- return $base . "\{$self->{parent_key}\}";
- }
- return $base . "\[$self->{parent_key}\]";
- }
- return '$db->';
-}
-
sub STORE {
##
# Store single hash key/value or array element in database.
my $value = ($self->_root->{filter_store_value} && !ref($_[2]))
? $self->_root->{filter_store_value}->($_[2])
: $_[2];
-
- if ( my $afh = $self->_root->{audit_fh} ) {
- unless ( $self->_type eq SIG_ARRAY && $key eq 'length' ) {
- my $lhs = $self->_find_parent;
- if ( $self->_type eq SIG_HASH ) {
- $lhs .= "\{$key\}";
- }
- else {
- $lhs .= "\[$_[3]\]";
- }
-
- my $rhs;
-
- my $r = Scalar::Util::reftype( $_[2] ) || '';
- if ( $r eq 'HASH' ) {
- $rhs = '{}';
- }
- elsif ( $r eq 'ARRAY' ) {
- $rhs = '[]';
- }
- else {
- $rhs = "'$_[2]'";
- }
-
- flock( $afh, LOCK_EX );
- print( $afh "$lhs = $rhs; # " . localtime(time) . "\n" );
- flock( $afh, LOCK_UN );
- }
- }
my $md5 = $DIGEST_FUNC->($key);
##
# Add key/value to bucket list
##
- my $result = $self->_add_bucket( $tag, $md5, $key, $value, $_[3] || $key );
-
+ my $result = $self->_add_bucket( $tag, $md5, $key, $value );
+
$self->unlock();
return $result;
##
# Get value from bucket list
##
- my $result = $self->_get_bucket_value( $tag, $md5, $key );
+ my $result = $self->_get_bucket_value( $tag, $md5 );
$self->unlock();
##
# Delete bucket
##
- my $value = $self->_get_bucket_value( $tag, $md5, $key );
+ my $value = $self->_get_bucket_value( $tag, $md5 );
if ($value && !ref($value) && $self->_root->{filter_fetch_value}) {
$value = $self->_root->{filter_fetch_value}->($value);
}
package DBM::Deep::_::Root;
-use Fcntl;
-
sub new {
my $class = shift;
my ($args) = @_;
$self->{file_offset} = tell( $self->{fh} );
}
- if ( $self->{audit_file} && !$self->{audit_fh} ) {
- my $flags = O_WRONLY | O_APPEND | O_CREAT;
-
- my $fh;
- sysopen( $fh, $self->{audit_file}, $flags )
- or die "Cannot open audit file: $!";
-
- my $old = select $fh;
- $|=1;
- select $old;
-
- $self->{audit_fh} = $fh;
- }
-
return $self;
}
B<NOTE>: This parameter is considered deprecated and should not be used anymore.
-=item * audit_file / audit_fh
-
-If you set either of these, an auditlog will be written to. If you set
-audit_file, audit_fh will be set to the open() on the audit_file.
-
-The auditing information will look something like:
-
- $db->{foo} = 'floober';
- $db->{bar} = {};
- $db->{bar}{a} = [];
- $db->{bar}{a}[0] = '5';
-
-The idea is that if your DB file is corrupted, you can recover it by doing
-something like:
-
- my $db = DBM::Deep->new( $new_filename );
- do( $audit_file );
-
-It is your responsability to make sure that the same auditlog is opened with the
-same DB file every time the DB file is opened. This will change when 1.00 is
-released.
-
=back
=head1 TIE INTERFACE