++ed by:
Lukas Mai


Scope::OnExit::Wrap - run code on scope exit (with pure Perl fallback)


    my $var = foo();
    my $guard = on_scope_exit {
  }  # scope exit: do_something($var) is run now


This module is a thin wrapper around Scope::OnExit, which is written in C. If Scope::OnExit is not available, it provides its own pure Perl implementation equivalent to End (which adds a tiny bit of overhead: an object is constructed and its destructor invoked).


on_scope_exit BLOCK

(This function is exported by default.)

Arranges for BLOCK to be executed when the surrounding scope is exited (whether it reaches the end normally, by last, by return, or by throwing an exception).

For compatibility with the XS and pure Perl implementations, you must save the return value of on_scope_exit in a lexical (my) variable, which you then ignore (i.e. don't do anything with the variable afterwards).

(The XS code in Scope::OnExit will register the block directly and not return anything useful, but the pure Perl substitute will return an object here whose destructor invokes the block.)


Scope::OnExit, End


Lukas Mai, <l.mai at web.de>


Copyright 2013 Lukas Mai.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

Hosting generously
sponsored by Bytemark