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';
46 push @reset_funcs, sub {
47 my $dbh = DBI->connect(
48 "dbi:SQLite:dbname=$filename", '', '',
51 my $filename = 'etc/sqlite_tables.sql';
52 open my $fh, '<', $filename
53 or die "Cannot open '$filename' for reading: $!\n";
57 foreach my $line ( split ';', $sql ) {
58 $dbh->do( "$line" ) if $line =~ /\S/;
63 dsn => "dbi:SQLite:dbname=$filename",
70 if ( $ENV{TEST_MYSQL_DSN} ) {
71 push @reset_funcs, sub {
72 my $dbh = DBI->connect(
74 $ENV{TEST_MYSQL_USER},
75 $ENV{TEST_MYSQL_PASS},
78 my $filename = 'etc/mysql_tables.sql';
79 open my $fh, '<', $filename
80 or die "Cannot open '$filename' for reading: $!\n";
84 foreach my $line ( split ';', $sql ) {
85 $dbh->do( "$line" ) if $line =~ /\S/;
90 dsn => $ENV{TEST_MYSQL_DSN},
91 user => $ENV{TEST_MYSQL_USER},
92 password => $ENV{TEST_MYSQL_PASS},
98 return unless @extra_args;
99 my @these_args = @{ shift @extra_args };
100 if ( my $reset = shift @reset_funcs ) {
105 @these_args, @args, @_,