Variable::OnDestruct(3pm)

NAME
Variable::OnDestruct - Call a subroutine on destruction of a variable.

VERSION
version 0.09

SYNOPSIS
    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) };

DESCRIPTION
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.

FUNCTIONS

  on_destruct $variable, \&sub;
This function adds a destructor to a variable. It is exported by default.

  on_destruct_fifo $variable, \&sub;
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.

AUTHOR
Leon Timmermans <fawaka@gmail.com>

COPYRIGHT AND LICENSE
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.