++ed by:

2 PAUSE users
1 non-PAUSE user.

Christian Jaeger
and 1 contributors


FP::Weak - utilities to weaken references


 use FP::Weak;

 sub foo {
     my $f; $f= sub { my ($n,$tot)=@_; $n < 100 ? &$f($n+1, $tot+$n) : $tot };
     Weakened $f

 is foo->(10, 0), 4905;
 # the subroutine returned from foo will not be leaked.


weaken <location>

`Scalar::Util`'s `weaken`, unless one of the `with_..` development utils are used (or `$FP::Weak::weaken` is changed).

Weakened <location>

Calls `weaken <location>` after copying the reference, then returns the unweakened reference.

Keep <location>

Protect <location> from being weakened by accessing elements of `@_`.

Optionally exported development utils:

noweaken ($var), noWeakened ($var)

No-ops. The idea is to prefix the weakening ops with 'no' to disable them.

warnweaken ($var), warnWeakened ($var)

Give a warning in addition to the weakening operation.

cluckweaken ($var), cluckWeakened ($var)

Give a warning with backtrace in addition to the weakening operation.

with_noweaken { code }, &with_noweaken ($proc)
with_warnweaken { code } (and same as above)
with_cluckweaken { code }

Within their dynamic scope, globally change `weaken` to one of the alternatives

do_weaken (1|0|"yes"|"no"|"on"|"off"|"warn"|"cluck")

Turn weakening on and off (unscoped, 'persistently').