Util::Scoped - Execute arbitrary code upon object destruction
use Util::Scoped; sub some_function { my $reset = new Util::Scoped(sub { $value = 0; }); ... $value = 1; ... ## Upon destruction of $reset $value is set back to zero }
The first parameter of the new
function is a code reference. Upon
destruction, the code reference is executed in the DESTROY
function.