# These are the defaults to be optionally overridden below
my $self = bless {
type => TYPE_HASH,
- engine => DBM::Deep::Engine->new,
+ engine => DBM::Deep::Engine->new( $args ),
base_offset => undef,
}, $class;
- # Strip out the node-level parameters before passing $args to
- # the root's constructor.
+ # Grab the parameters we want to use
foreach my $param ( keys %$self ) {
next unless exists $args->{$param};
- $self->{$param} = delete $args->{$param}
+ $self->{$param} = $args->{$param}
}
# locking implicitly enables autoflush
filter_store_value => undef,
filter_fetch_key => undef,
filter_fetch_value => undef,
- %$args,
}, $class;
+ # Grab the parameters we want to use
+ foreach my $param ( keys %$self ) {
+ next unless exists $args->{$param};
+ $self->{$param} = $args->{$param}
+ }
+
if ( $self->{fh} && !$self->{file_offset} ) {
$self->{file_offset} = tell( $self->{fh} );
}
max_buckets => 16,
}, $class;
+ # Grab the parameters we want to use
+ foreach my $param ( keys %$self ) {
+ next unless exists $args->{$param};
+ $self->{$param} = $args->{$param}
+ }
+
$self->precalc_sizes;
return $self;
}
-sub write_file_signature {
+sub write_file_header {
my $self = shift;
my ($obj) = @_;
return;
}
-sub read_file_signature {
+sub read_file_header {
my $self = shift;
my ($obj) = @_;
flock $fh, LOCK_EX;
unless ( $obj->{base_offset} ) {
- my $bytes_read = $self->read_file_signature( $obj );
+ my $bytes_read = $self->read_file_header( $obj );
##
- # File is empty -- write signature and master index
+ # File is empty -- write header and master index
##
if (!$bytes_read) {
- $self->write_file_signature( $obj );
+ $self->write_file_header( $obj );
$obj->{base_offset} = $self->_request_space(
$obj, $self->tag_size( $self->{index_size} ),
$obj->{base_offset} = $bytes_read;
##
- # Get our type from master index signature
+ # Get our type from master index header
##
my $tag = $self->load_tag($obj, $obj->_base_offset)
or $obj->_throw_error("Corrupted file, no master index record");
##
use strict;
use Test::More tests => 3;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+
+use t::common qw( new_fh );
diag "Testing DBM::Deep against Perl $] located at $^X";
##
# basic file open
##
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = eval {
local $SIG{__DIE__};
DBM::Deep->new( $filename );
use strict;
use Test::More tests => 32;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
##
##
use strict;
use Test::More tests => 2;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
type => DBM::Deep->TYPE_HASH
use strict;
use Test::More tests => 109;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
type => DBM::Deep->TYPE_ARRAY
##
use strict;
use Test::More tests => 2;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
- type => DBM::Deep->TYPE_ARRAY
+ type => DBM::Deep->TYPE_ARRAY,
);
##
use strict;
use Test::More tests => 6;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
##
# test a corrupted file
} qr/DBM::Deep: Corrupted file, no master index record/, "Fail if there's no master index record";
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my %hash;
tie %hash, 'DBM::Deep', $filename;
undef %hash;
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my @array;
tie @array, 'DBM::Deep', $filename;
undef @array;
##
use strict;
use Test::More tests => 4;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
locking => 1,
##
use strict;
use Test::More tests => 5;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $max_levels = 1000;
##
use strict;
use Test::More tests => 3;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $max_levels = 1000;
##
use strict;
use Test::More tests => 14;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
);
##
use strict;
use Test::More tests => 14;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
{
my $clone;
##
use strict;
use Test::More tests => 2;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-
my ($before, $after);
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
autoflush => 1
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
autoflush => 1
##
use strict;
use Test::More tests => 17;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new(
file => $filename,
);
##
use strict;
use Test::More tests => 14;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $salt = 38473827;
##
use strict;
use Test::More tests => 32;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
##
##
use strict;
use Test::More tests => 2;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
##
##
use strict;
use Test::More tests => 2;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-
my $struct;
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
##
use strict;
use Test::More tests => 6;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh2, LOCK_UN;
+my ($fh2, $filename2) = new_fh();
my $db2 = DBM::Deep->new( $filename2 );
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
##
use strict;
use Test::More tests => 11;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-
##
# testing the various modes of opening a file
##
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my %hash;
my $db = tie %hash, 'DBM::Deep', $filename;
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my %hash;
my $db = tie %hash, 'DBM::Deep', {
file => $filename,
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my @array;
my $db = tie @array, 'DBM::Deep', $filename;
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my @array;
my $db = tie @array, 'DBM::Deep', {
file => $filename,
is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
}
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
throws_ok {
tie my %hash, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
use strict;
use Test::More tests => 7;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir();
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
{
my %hash;
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );
throws_ok {
##
use strict;
use Test::More tests => 13;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
##
my $max_keys = 1000;
-my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh2, LOCK_UN;
+my ($fh2, $filename2) = new_fh();
{
my $db = DBM::Deep->new( $filename2 );
use strict;
use Test::More tests => 7;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
$db->{key1} = "value1";
}
use Test::More tests => 64;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
{
my $db = DBM::Deep->new(
file => $filename,
is( $db->{unblessed}{b}[2], 3 );
}
-my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh2, LOCK_UN;
+my ($fh2, $filename2) = new_fh();
{
my $db = DBM::Deep->new(
file => $filename2,
# longer named class (FooFoo) and replacing key in db file, then validating
# content after that point in file to check for corruption.
##
- my ($fh3, $filename3) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh3, LOCK_UN;
+ my ($fh3, $filename3) = new_fh();
my $db = DBM::Deep->new(
file => $filename3,
autobless => 1,
use strict;
use Test::More tests => 5;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-
use Scalar::Util qw( reftype );
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my %hash;
my $obj = tie %hash, 'DBM::Deep', $filename;
}
{
- my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
- flock $fh, LOCK_UN;
+ my ($fh, $filename) = new_fh();
my @array;
my $obj = tie @array, 'DBM::Deep', $filename;
use Test::More tests => 10;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $x = 25;
{
use strict;
use Test::More tests => 11;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
# Create the datafile to be used
{
use strict;
use Test::More tests => 3;
-use File::Temp qw( tempfile );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1 );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new({
file => $filename,
autoflush => 1,
use strict;
use Test::More tests => 7;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
{
use strict;
use Test::More tests => 16;
use Test::Exception;
-use File::Temp qw( tempfile tempdir );
-use Fcntl qw( :flock );
+use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my $dir = tempdir( CLEANUP => 1 );
-my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
-flock $fh, LOCK_UN;
+my ($fh, $filename) = new_fh();
my $db = DBM::Deep->new( $filename );
my %hash = (
--- /dev/null
+#!/usr/bin/perl -l
+
+##
+# DBM::Deep Test
+#
+# Test for interference from -l on the commandline.
+##
+use strict;
+use Test::More tests => 4;
+use Test::Exception;
+use t::common qw( new_fh );
+
+use_ok( 'DBM::Deep' );
+
+my ($fh, $filename) = new_fh();
+my $db = DBM::Deep->new( $filename );
+
+##
+# put/get key
+##
+$db->{key1} = "value1";
+is( $db->get("key1"), "value1", "get() works with hash assignment" );
+is( $db->fetch("key1"), "value1", "... fetch() works with hash assignment" );
+is( $db->{key1}, "value1", "... and hash-access also works" );
--- /dev/null
+package t::common;
+
+use 5.6.0;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.01';
+
+use base 'Exporter';
+our @EXPORT_OK = qw(
+ new_fh
+);
+
+use File::Spec ();
+use File::Temp qw( tempfile tempdir );
+use Fcntl qw( :flock );
+
+my $parent = $ENV{WORK_DIR} || File::Spec->tmpdir;
+my $dir = tempdir( CLEANUP => 1, DIR => $parent );
+
+sub new_fh {
+ my ($fh, $filename) = tempfile( 'tmpXXXX', DIR => $dir );
+
+ # This is because tempfile() returns a flock'ed $fh on MacOSX.
+ flock $fh, LOCK_UN;
+
+ return ($fh, $filename);
+}
+#END{<>}
+1;
+__END__
+