NAME

FP::Weak - utilities to weaken references

SYNOPSIS

use FP::Weak;

sub stream_foo {
    my ($s)=@_;
    weaken $_[0];
    my $f; $f= sub { ... &$f ... };
    Weakened $f
}

my $x = do {
    my $s= somestream;
    stream_foo (Keep $s);
    $s->first
};

DESCRIPTION

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').