NAME

Value::Canary - Callbacks for value destruction

VERSION

version 0.01

SYNOPSIS

    use Value::Canary;

    my $i = 0;

    {
        my $value = 42;
        canary $value, sub { $i++ };

        ...

        # $i is still 0
    } # end of scope causes $value to be destroyed and the callback to be invoked

    # $i is now 1

DESCRIPTION

This module provides an easy way to get notified as soon as a value is being destroyed. This is mostly handy for debugging purposes, when you want to find out which code is throwing the value you passed in away, instead of using it for something useful.

FUNCTIONS

canary ($variable, $callback?)

Registers a $callback to be called as soon as $variable is being destroyed. The callback will be invoked with a reverence to the $variable as its only argument. If no callback is given, a default callback will be used. The default callback will warn with a full stack trace of where the value is being destroyed, as well as the message "$value destroyed".

This function is exported by default. See Sub::Exporter on how to customize how exactly exporting happens.

SEE ALSO

Variable::Magic

Scope::Guard

Object::Deadly

AUTHOR

  Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2009 by Florian Ragwitz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.