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;
39 [ file => $filename ],
43 # eval { require DBD::SQLite; };
49 if ( $ENV{TEST_MYSQL_DSN} ) {
50 push @reset_funcs, sub {
51 my $dbh = DBI->connect(
53 $ENV{TEST_MYSQL_USER},
54 $ENV{TEST_MYSQL_PASS},
57 my $filename = 'etc/mysql_tables.sql';
58 open my $fh, '<', $filename
59 or die "Cannot open '$filename' for reading: $!\n";
63 foreach my $line ( split ';', $sql ) {
64 $dbh->do( "$line" ) if $line =~ /\S/;
69 dsn => $ENV{TEST_MYSQL_DSN},
70 user => $ENV{TEST_MYSQL_USER},
71 password => $ENV{TEST_MYSQL_PASS},
77 return unless @extra_args;
78 my @these_args = @{ shift @extra_args };
79 if ( my $reset = shift @reset_funcs ) {
84 @these_args, @args, @_,