The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Unwind::Protect - Run code after other code, even with exceptions

VERSION

version 0.01

SYNOPSIS

    ++$depth;
    
    unwind_protect { unsafe_function() }
      after => sub { --$depth };

DESCRIPTION

Sometimes you need to run code after some other code. Two complications are preserving list; scalar; or void context, and dealing with exceptions. Unwind::Protect handles both for you.

unwind-protect exists in Common Lisp with nearly the same interface.

I strive to handle exceptions properly. It's not easy, because of all the tools Perl provides. $SIG{__DIE__} and caller make this code somewhat hairy. If you provide me a failing test where the unwind_protect stack frame is inadvertantly exposed, I will try to fix it.

FUNCTIONS

unwind_protect CODE, ARGS

unwind_protect takes a code block (similar to grep) then some named arguments. Currently the only named argument that is accepted is after which is a coderef to run after the primary code.

AUTHOR

Shawn M Moore, sartak@bestpractical.com

SEE ALSO

Context::Preserve