Name
SPVM::File::Temp - Temporary Files and Directories
Description
File::Temp class in SPVM has methods to create temporary files and directories.
Usage
use File::Temp;
# Create a temporary file
my $tmp_fh = File::Temp->new;
my $tmp_filename = $tmp_fh->filename;
$tmp_fh->print("Hello World!");
# With options
my $tmp_fh = File::Temp->new({DIR => $dir, TEMPLATE => $template, UNLINK => 0});
# Create a temporary directory
my $tmp_dir = File::Temp->newdir;
my $tmp_dirname = $tmp_dir->dirname;
Super Class
Fields
filename
has filename : ro string;
A file path. This is the path of a temporary file.
process_id
has process_id : int;
A process ID. This is the process ID of the process that creates a temporary file.
Class Methods
new
static method new : File::Temp ($options : object[] = undef);
Creates a new File::Temp object given the options $options, and returns it.
"process_id" field is set to the current process ID.
new Options
DIR option
DIR
: string = undef
A directory where a temproary file is created.
TMPDIR option
TMPDIR
: Int = 0
If this value is a true value and the value of "TEMPLATE option" is defined but the value of "DIR option" is not defined, the temporary directory in the system is used as the value of "DIR option".
TEMPLATE option
TEMPLATE
: string = undef
A template. This is the template for the base name of the temporary file and contains multiple X
such as tempXXXXX
.
SUFFIX option
SUFFIX
: string = ""
An extension of the temprary file such as .tmp
.
UNLINK option
UNLINK
: Int = 1
If this value is a true value, the program tries to remove the temporary file when this instance is destroyed.
See "DESTROY" method for details.
newdir
static method newdir : File::Temp::Dir ($options : object[] = undef);
Calls File::Temp::Dir#new method given the options $options, and retunrs its return value.
DESTROY
method DESTROY : void ();
If the file handle is opened, closes the file descriptor of the temporary file.
If the vlaue of "UNLINK option" is a true value and the current process ID is the same as "process_id" field, removes the temproary file.
Repository
Author
Yuki Kimoto kimoto.yuki@gmail.com
Copyright & License
Copyright (c) 2023 Yuki Kimoto
MIT License