Commit | Line | Data |
f19b7e37 |
1 | package # Hide from PAUSE |
2 | t::common; |
fde3db1a |
3 | |
b48ae6ec |
4 | use 5.006_000; |
fde3db1a |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
9 | our $VERSION = '0.01'; |
10 | |
11 | use base 'Exporter'; |
12 | our @EXPORT_OK = qw( |
13 | new_fh |
14 | ); |
15 | |
16 | use File::Spec (); |
17 | use File::Temp qw( tempfile tempdir ); |
18 | use Fcntl qw( :flock ); |
19 | |
20 | my $parent = $ENV{WORK_DIR} || File::Spec->tmpdir; |
21 | my $dir = tempdir( CLEANUP => 1, DIR => $parent ); |
f19b7e37 |
22 | #my $dir = tempdir( DIR => '.' ); |
fde3db1a |
23 | |
24 | sub new_fh { |
0856d3d8 |
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 |
33 | 1; |
34 | __END__ |