Scope::local_OnExit - an execute-at-scope-exit mechanism using local
local
our $onExit; use Scope::local_OnExit; ... sub SomethingCritical{ local$OnExit=\&release_lock; obtain_lock; ... }
This very short module provides a pure-perl mechanism for executing perl code at scope exit, at the time that the "old value" is returned to the tied variable.
Instead of
on_scope_exit { do_something($var) };
one would code
local$OnExit=sub{ do_something($var) };
the scalar package variable $OnExit is tied into the package.
$OnExit
To tie a different variable than $OnExit, use empty parentheses on the use line to suppress import and tie the variable of your selection.
use
import
initial draft written March 2010 and published on a blog and submitted to the module-authors mailing list for comment.
This version (April 2010) reflects comments received.
Scope::OnExit provides the same functionality but must be compiled.
David Nicol davidnico@cpan.org
Please comment via rt.cpan.org
Copyright (C) 2010 by David Nicol / TipJar LLC
Released under the http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0 Unported License
Leaving this section in the documentation in your installed library is sufficient attribution.
To install Scope::local_OnExit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scope::local_OnExit
CPAN shell
perl -MCPAN -e shell install Scope::local_OnExit
For more information on module installation, please visit the detailed CPAN module installation guide.