1 package # Hide from PAUSE
5 use warnings FATAL => 'all';
14 use File::Temp qw( tempfile tempdir );
15 use Fcntl qw( :flock );
17 my $parent = $ENV{WORK_DIR} || File::Spec->tmpdir;
18 my $dir = tempdir( CLEANUP => 1, DIR => $parent );
21 my ($fh, $filename) = tempfile( 'tmpXXXX', DIR => $dir, UNLINK => 1 );
23 # This is because tempfile() returns a flock'ed $fh on MacOSX.
26 return ($fh, $filename);
31 my ($fh, $filename) = new_fh();
36 unless ( $ENV{NO_TEST_FILE} ) {
37 push @reset_funcs, undef;
43 if ( $ENV{TEST_SQLITE} ) {
44 (undef, my $filename) = new_fh();
45 # $filename = 'test.db';
47 push @reset_funcs, sub {
48 my $dbh = DBI->connect(
49 "dbi:SQLite:dbname=$filename", '', '',
52 my $filename = 'etc/sqlite_tables.sql';
53 open my $fh, '<', $filename
54 or die "Cannot open '$filename' for reading: $!\n";
58 foreach my $line ( split ';', $sql ) {
59 $dbh->do( "$line" ) if $line =~ /\S/;
64 dsn => "dbi:SQLite:dbname=$filename",
71 if ( $ENV{TEST_MYSQL_DSN} ) {
72 push @reset_funcs, sub {
73 my $dbh = DBI->connect(
75 $ENV{TEST_MYSQL_USER},
76 $ENV{TEST_MYSQL_PASS},
79 my $filename = 'etc/mysql_tables.sql';
80 open my $fh, '<', $filename
81 or die "Cannot open '$filename' for reading: $!\n";
85 foreach my $line ( split ';', $sql ) {
86 $dbh->do( "$line" ) if $line =~ /\S/;
91 dsn => $ENV{TEST_MYSQL_DSN},
92 user => $ENV{TEST_MYSQL_USER},
93 password => $ENV{TEST_MYSQL_PASS},
99 return unless @extra_args;
100 my @these_args = @{ shift @extra_args };
101 if ( my $reset = shift @reset_funcs ) {
105 DBM::Deep->new( @these_args, @args, @_ )