newdir#

Construct a File::Temp::Dir object wrapping a newly created temporary directory.

תקציר#

my $dir = File::Temp->newdir;
my $dir = File::Temp->newdir('buildXXXXXX', DIR => '/var/tmp', CLEANUP => 0);

מה מוחזר#

A blessed File::Temp::Dir object. It stringifies to the directory path, and its destructor removes the directory tree when CLEANUP is true (the default) and the current process matches the creating pid.

Options#

Same as tempdir except CLEANUP defaults to true. The object records the creator pid so child processes do not accidentally delete a parent’s directory on exit.

דוגמאות#

my $dir = File::Temp->newdir;
open my $fh, '>', "$dir/scratch";           # $dir stringifies

## $dir and its contents are removed when $dir goes out of scope
my $dir = File::Temp->newdir(CLEANUP => 0); # keep the tree

מקרי קצה#

  • Forked children do not clean up the parent’s directory.

  • $File::Temp::KEEP_ALL = 1 suppresses removal on destruction.

הבדלים מן ה-upstream#

Fully compatible with upstream File::Temp 0.2312.

ראו גם#

  • tempdir - functional counterpart returning a plain path string.

  • dirname - method on the returned object returning the path.

  • unlink_on_destroy - toggle cleanup on a per-object basis.

  • File::Temp->new - file counterpart.