Sub::ScopeFinalizer - execute a code on exiting scope.
Version 0.02
use Sub::ScopeFinalizer qw(scope_finalizer); { my $anchor = scope_finalizer { print "put clean up code here.\n"; }; print "running block.\n"; }
Sub::ScopeFinalizer invoke BLOCK, triggered by leaving a scope. It is similar to destructor or finally clause.
This module exports one function, scope_finalizer.
scope_finalizer
$o = scope_finalizer BLOCK; $o = scope_finalizer BLOCK { args =>[...] };
Create a finalizer object. This is shortcut to invoke Sub::ScopeFinalizer->new(...).
Sub::ScopeFinalizer->new(...)
BLOCK will be executed when object is destroyed. In other words, process just exits a scope which object is binded on.
Second argument is optional hashref. $opts->{args} can contain argument for BLOCK as ARRAYref.
If you only call this function without bind, BLOCK is executed immediately because object is destroyed as soon as return from function. Don't forget to bind.
Create a finalizer object. You must bind it with variable on scope.
See "scope_finalizer".
$obj->raise(); $obj->raise({args=>[...]});
Invoke finalizer before it run automatically. This method disables default invokation on scope leaving.
This method takes one argument as optional hashref. $opts->{args} can contain argument for BLOCK as ARRAYref. if $opts->{args} is passed, args parameter on constructor is ignored.
$obj->disable(); $obj->disable($flag);
Turn off BLOCK invoking. If optional argument $flag is passwd and it is false, cancel disabling, that is, enable invoking.
YAMASHINA Hio, <hio at cpan.org>
<hio at cpan.org>
Please report any bugs or feature requests to bug-sub-scopescope_finalizer at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sub-ScopeFinalizer. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-sub-scopescope_finalizer at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Sub::ScopeFinalizer
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Sub-ScopeFinalizer
CPAN Ratings
http://cpanratings.perl.org/d/Sub-ScopeFinalizer
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sub-ScopeFinalizer
Search CPAN
http://search.cpan.org/dist/Sub-ScopeFinalizer
Copyright 2006 YAMASHINA Hio, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Sub::ScopeFinalizer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::ScopeFinalizer
CPAN shell
perl -MCPAN -e shell install Sub::ScopeFinalizer
For more information on module installation, please visit the detailed CPAN module installation guide.