##
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 );
##
# Create structure in $db
##
-$db->import(
- hash1 => {
- subkey1 => "subvalue1",
- subkey2 => "subvalue2",
- },
+$db->import({
+ hash1 => {
+ subkey1 => "subvalue1",
+ subkey2 => "subvalue2",
+ },
hash2 => {
subkey3 => 'subvalue3',
},
-);
+});
is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
$db->{copy} = $db->{hash2};
is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" );
-
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 );
+ my $db = DBM::Deep->new( file => $filename2, fh => $fh2, );
$db->{foo} = [ 1 .. 3 ];
for ( 0 .. $max_keys ) {
$db->{'foo' . $_} = $db->{foo};
}
+ ## Rewind handle otherwise the signature is not recognised below.
+ ## The signature check should probably rewind the fh?
+ seek $db->_get_self->_engine->storage->{fh}, 0, 0;
}
{
- my $db = DBM::Deep->new( $filename2 );
+ my $db = DBM::Deep->new( fh => $fh2, );
my $base_offset = $db->{foo}->_base_offset;
my $count = -1;