ok( $db->get("key1") eq "value222222222222222222222222" );
-##
-# close, delete file, exit
-##
-undef $db;
-unlink "t/test.db";
-exit(0);
-
sub my_digest {
##
# Warning: This digest function is for testing ONLY
##
use strict;
use Test::More tests => 5;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
-
-unlink "t/test2.db";
-my $db2 = DBM::Deep->new( "t/test2.db" );
-
-##
-# Create structure in $db
-##
-$db->import(
- hash1 => {
- subkey1 => "subvalue1",
- subkey2 => "subvalue2"
- }
-);
-
-is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
-is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
-
-##
-# Cross-ref nested hash accross DB objects
-##
-$db2->{copy} = $db->{hash1};
-
-##
-# close, delete $db
-##
-undef $db;
-unlink "t/test.db";
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db2 = DBM::Deep->new( $filename2 );
+
+{
+ my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+ my $db = DBM::Deep->new( $filename );
+
+ ##
+ # Create structure in $db
+ ##
+ $db->import(
+ hash1 => {
+ subkey1 => "subvalue1",
+ subkey2 => "subvalue2"
+ }
+ );
+
+ is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
+ is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
+
+ ##
+ # Cross-ref nested hash accross DB objects
+ ##
+ $db2->{copy} = $db->{hash1};
+}
##
# Make sure $db2 has copy of $db's hash structure
tie my %hash, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
-unlink "t/test.db";
throws_ok {
tie my @array, 'DBM::Deep', [ file => $filename ];
} qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
-unlink "t/test.db";
throws_ok {
tie my %hash, 'DBM::Deep', undef, file => $filename;
} qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
-unlink "t/test.db";
throws_ok {
tie my @array, 'DBM::Deep', undef, file => $filename;
} qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";
##
use strict;
use Test::More tests => 13;
+use File::Temp qw( tempfile tempdir );
use_ok( 'DBM::Deep' );
-unlink "t/test.db";
-my $db = DBM::Deep->new( "t/test.db" );
+my $dir = tempdir( CLEANUP => 1 );
+my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
+my $db = DBM::Deep->new( $filename );
##
# Create structure in $db
my $max_keys = 1000;
-unlink 't/test2.db';
+my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
{
- my $db = DBM::Deep->new( 't/test2.db' );
+ my $db = DBM::Deep->new( $filename2 );
$db->{foo} = [ 1 .. 3 ];
for ( 0 .. $max_keys ) {
}
{
- my $db = DBM::Deep->new( 't/test2.db' );
+ my $db = DBM::Deep->new( $filename2 );
my $base_offset = $db->{foo}->_base_offset;
my $count = -1;