Perl::AtEndOfScope - run some code when a variable goes out of scope
use Perl::AtEndOfScope; use Cwd; { my $restorecwd=Perl::AtEndOfScope->new( sub{chdir $_[0]}, getcwd ); chdir '/path/to/some/directory'; ... } # now we are back to the old cwd
It's often necessary to do some cleanup at the end of a scope. This module creates a Perl object and executes arbitrary code when the object goes out of scope.
the constructor. The code reference passed in $sub is called with @args as parameter list when the object is destroyed.
the destructor.
Not an Exporter.
Torsten Foertsch, <torsten.foertsch@gmx.net>
Copyright (C) 2005 by Torsten Foertsch
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Perl::AtEndOfScope, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::AtEndOfScope
CPAN shell
perl -MCPAN -e shell install Perl::AtEndOfScope
For more information on module installation, please visit the detailed CPAN module installation guide.