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