do shit in `$dir` $dir on Linux will be something like /tmp/perl-Some-Package-maybewith-a-VERSION-AFG14561/ so if it crashes and leaves a tempdir behind, you will know who left that tempdir behind and have a way of cleaning it up.

When $tempdir is destroyed, $dir will be cleaned;

Additionally:

$dir->run_once_in(sub{
...
});

Is there for people who don't trust scope auto-cleansing and want to know when the dir is reaped.

Additionally, this code can be run in a tight loop creating and destroying lots of similary named tempdirs without risk of conflict.

Toggle the preservation of the tempdir after it goes out of scope or is otherwise indicated for cleaning.

$instance->preserve(); # tempdir is now preserved after cleanup
$instance->preserve(0); # tempdir is purged at cleanup
$instance->preserve(1); # tempdir is preserved after cleanup

Note that in run_once_in, a new tempdir is created and set for this modules consumption for each run of run_once_in, regardless of this setting. All this setting will do, when set, will prevent each instance being reaped from the filesystem.

Thus:

$dir->preserve(1);
for( 1..10 ){
$dir->run_once_in(sub{
});
}

Will create 10 temporary directories on your filesystem and not reap them.