unlink_on_destroy#
Toggle or query whether a File::Temp object unlinks its file when destroyed.
Synopsis#
my $flag = $tmp->unlink_on_destroy; # getter
$tmp->unlink_on_destroy(0); # keep the file
$tmp->unlink_on_destroy(1); # remove on destruction
What you get back#
The new (or current) flag value as an integer: 1 if the file
will be removed when the object is destroyed, 0 otherwise.
Examples#
my $tmp = File::Temp->new;
$tmp->unlink_on_destroy(0);
## $tmp->filename survives after $tmp goes out of scope
Edge cases#
Called on something that is not a
File::Tempobject: returns1without touching state.Setting to a true value on an object whose file is no longer tracked does not re-register it.
Differences from upstream#
The flag is stored in an internal map rather than the blessed glob’s hash slot. Code that pokes at
%{*$fh}directly will not observe the flag; use the method. Covered byt/81-xs-native/File-Temp/*.t.
See also#
File::Temp->new— constructor whose default isUNLINK => 1.cleanup— force-drain all registered cleanups now.unlink0— verified unlink used internally by scalar-context tempfile.