Variable::OnDestruct - Call a subroutine on destruction of a variable.
version 0.09
use Variable::OnDestruct; on_destruct $var, sub { do_something() }; on_destruct @array, sub { do_something_else() }; on_destruct %array, sub { hashes_work_too() }; on_destruct &$sub, sub { so_do_closures($but_not_normal_subs) }; on_destruct *$glob, sub { and_even_globs($similar_caveats_as_subs_though) };
This module allows you to let a function be called when a variable gets destroyed. The destructor will work not only on scalars but also on arrays, hashes, subs and globs. For the latter two you should realize that most of them aren't scoped like normal variables. Subs for example will only work like you expect them to when they are closures.
This function adds a destructor to a variable. It is exported by default.
This function adds a destructor to a variable. When adding multiple destructors, this will execute them in fifo order, unlike on_destruct which will handle them in lifo order.
on_destruct
Leon Timmermans <fawaka@gmail.com>
This software is copyright (c) 2009 by Leon Timmermans.
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 Variable::OnDestruct, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Variable::OnDestruct
CPAN shell
perl -MCPAN -e shell install Variable::OnDestruct
For more information on module installation, please visit the detailed CPAN module installation guide.