r589@rob-kinyons-computer-2 (orig r10513): rkinyon | 2008-01-10 23:43:55 -0500
[dbsrgits/DBM-Deep.git] / t / common.pm
CommitLineData
2003fa09 1package # Hide from PAUSE
2 t::common;
fde3db1a 3
b48ae6ec 4use 5.006_000;
fde3db1a 5
6use strict;
7use warnings;
8
9our $VERSION = '0.01';
10
11use base 'Exporter';
12our @EXPORT_OK = qw(
13 new_fh
14);
15
16use File::Spec ();
17use File::Temp qw( tempfile tempdir );
18use Fcntl qw( :flock );
19
20my $parent = $ENV{WORK_DIR} || File::Spec->tmpdir;
21my $dir = tempdir( CLEANUP => 1, DIR => $parent );
2003fa09 22#my $dir = tempdir( DIR => '.' );
fde3db1a 23
24sub new_fh {
2003fa09 25 my ($fh, $filename) = tempfile( 'tmpXXXX', DIR => $dir, UNLINK => 1 );
fde3db1a 26
27 # This is because tempfile() returns a flock'ed $fh on MacOSX.
28 flock $fh, LOCK_UN;
29
30 return ($fh, $filename);
31}
f72b2dfb 32
fde3db1a 331;
34__END__