Filter::Cleanup - Execute cleanup statements when scope closes, regardless of errors
version 0.03
use Filter::Cleanup; open my $fh, $file_path or die $!; cleanup { close $fh }; do_risky_stuff_with_fh($fh);
Defines a block of code to be evaluated once the current scope has completed execution. If an error is thrown during the execution of statements after the cleanup block, the error is trapped and rethrown after the cleanup block is executed.
cleanup
Filter::Cleanup
A cleanup block will execute ahead of any cleanups defined before it. That is, for a given scope, cleanup blocks will be called in the opposite order in which they were declared.
This module was originally implemented as a source filter (hence the name), but now uses Keyword::Declare.
Guard is implemented in XS and attaches a code block to the actual stack frame, ensuring it is executed regardless of how the scope was exited. In many cases, this may be preferable to the behavior of Filter::Cleanup, which will not be executed if the block calls exit or goto (note that last is handled correctly).
exit
goto
last
Jeff Ober sysread@fastmail.fm
Perl5
Jeff Ober <sysread@fastmail.fm>
This software is copyright (c) 2017 by Jeff Ober.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Filter::Cleanup, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Filter::Cleanup
CPAN shell
perl -MCPAN -e shell install Filter::Cleanup
For more information on module installation, please visit the detailed CPAN module installation guide.