WeakRef::Auto - Automatically makes references weaken
This document describes WeakRef::Auto version 0.01.
use WeakRef::Auto; autoweaken my $ref; # $ref is always weaken $ref = \$var; # $ref is weak
WeakRef::Auto provides autoweaken(), which keeps references weaken.
WeakRef::Auto
autoweaken()
Turns $var into auto-weaken variables, and keeps the values weak references.
$var can be an element of hashes or arrayes.
NOTE: the prototype of autoweaken() is "\$". That is, autoweakn($var) means &autoweaken(\$var).
"\$"
autoweakn($var)
&autoweaken(\$var)
Perl 5.8.1 or later.
autoweaken() does not work with tied variables, because autoweaken-ness is attached to the variable, not to the value refered by the variable, and tied variables iteract with their objects by values, not variables.
my $x = tie my %hash, 'Tie::StdHash'; autoweaken $hash{foo}; # $hash{foo} seems autoweaken. Really? # Actually, $hash{foo} is connected to $x->{foo}, # but there is no way to autoweaken($x->{foo}).
Patches are welcome.
Scalar::Util for a description of weak references.
Goro Fuji <gfuji(at)cpan.org>.
Copyright (c) 2008, Goro Fuji <gfuji(at)cpan.org>. Some rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WeakRef::Auto, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WeakRef::Auto
CPAN shell
perl -MCPAN -e shell install WeakRef::Auto
For more information on module installation, please visit the detailed CPAN module installation guide.