Value::Canary - Callbacks for value destruction


Value-Canary documentation  | view source Contained in the Value-Canary distribution.

Index


NAME

Top

Value::Canary - Callbacks for value destruction

VERSION

Top

version 0.01

SYNOPSIS

Top

    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

Top

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

Top

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

Top

Variable::Magic

Scope::Guard

Object::Deadly

AUTHOR

Top

  Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE

Top


Value-Canary documentation  | view source Contained in the Value-Canary distribution.