You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On Unixy systems it would put the file in /tmp. On Windows systems it should do the right thing as well.
Example:
perl -e '
{
package Path::Class::FileX;
use strict;
use warnings;
use base qw{Path::Class::File};
use File::Tempdir qw{};
sub temp {
my $self = shift; #class or object
my $tmpdir = File::Tempdir->new or die("Error: Could not create File::Tempdir object");
my $local_folder = $tmpdir->name or die("Error: Temporary directory not configured.");
my $file = $self->new($local_folder => "file.tmp"); #folder is unique
$file->{"__tmpdir"} = $tmpdir; #must keep tmpdir scope alive
return $file;
}
}
my $location;
{
my $file=Path::Class::FileX->temp;
print "$file\n";
$location="$file";
my $fh=$file->openw;
print $fh "Hello World!\n";
$fh->close;
print $file->slurp;
}
print "Exists\n" if -f $location; #file is out of scope so gone!
'
The text was updated successfully, but these errors were encountered:
It would be nice to provide temp file support
my $file = Path::Class::File->temp;
On Unixy systems it would put the file in /tmp. On Windows systems it should do the right thing as well.
Example:
perl -e '
{
package Path::Class::FileX;
use strict;
use warnings;
use base qw{Path::Class::File};
use File::Tempdir qw{};
sub temp {
my $self = shift; #class or object
my $tmpdir = File::Tempdir->new or die("Error: Could not create File::Tempdir object");
my $local_folder = $tmpdir->name or die("Error: Temporary directory not configured.");
my $file = $self->new($local_folder => "file.tmp"); #folder is unique
$file->{"__tmpdir"} = $tmpdir; #must keep tmpdir scope alive
return $file;
}
}
my $location;
{
my $file=Path::Class::FileX->temp;
print "$file\n";
$location="$file";
my $fh=$file->openw;
print $fh "Hello World!\n";
$fh->close;
print $file->slurp;
}
print "Exists\n" if -f $location; #file is out of scope so gone!
'
The text was updated successfully, but these errors were encountered: