FAKE_VG
}
+my $good_enough_file_temp;
+BEGIN {
+ $good_enough_file_temp = do {
+ no warnings;
+ local $@;
+ eval { File::Temp->VERSION('0.19'); 1 }
+ }
+}
+
sub new {
my ($class, %args) = @_;
my $self = { };
if (defined $exe_name) {
+ return 'File::Temp 0.19 is required to make a proper temporary directory'
+ unless $good_enough_file_temp;
$self->{tmp_dir_obj} = File::Temp->newdir(CLEANUP => 1);
$self->{tmp_dir} = $self->{tmp_dir_obj}->dirname;
$self->{tmp_file} = File::Spec->catfile($self->{tmp_dir}, $exe_name);
} else {
- $self->{tmp_file_obj} = File::Temp->new(UNLINK => 1);
- $self->{tmp_file} = $self->{tmp_file_obj}->filename;
+ # Can't use the OO interface if we don't wan't the file to be opened by
+ # default, but then we have to deal with cleanup ourselves.
+ local $^W = 0;
+ (undef, my $tmp_file) = File::Temp::tempfile(
+ TEMPLATE => 'fakevgXXXX',
+ TMPDIR => 1,
+ CLEANUP => 0,
+ OPEN => 0,
+ );
+ $self->{tmp_file} = $tmp_file;
my ($vol, $dir) = File::Spec->splitpath($self->{tmp_file});
$self->{tmp_dir} = File::Spec->catpath($vol, $dir, '');
}
bless $self, $class;
}
-sub path { $_[0]->{tmp_file} }
+sub path { $_[0]->{tmp_file} }
+
+sub dir { $_[0]->{tmp_dir} }
-sub dir { $_[0]->{tmp_dir} }
+sub DESTROY { 1 while unlink $_[0]->{tmp_file} }
1;