in reply to Per-object DESTROY

tilly's ReleaseAction has that, so you could collect "things to do on destruction" in your object with it:

use ReleaseAction 'on_release'; sub foo { ... my $actions = $self->actions; push @$actions, on_release { `rm -rf "$tmpdir"` }; };

And as soon as $self goes out of scope, hopefully all release actions will also fire. By attaching them to the object, you get the bonus option of optionally cancelling them should you have a reason to. Of course, you need to be careful that your closures don't close over your object, but you know that.