use Sub::Defer;
use B 'perlstring';
+use Scalar::Util qw(weaken);
use base qw(Exporter);
our @EXPORT = qw(quote_sub unquote_sub quoted_from_sub);
our %QUOTED;
+our %WEAK_REFS;
+
sub capture_unroll {
my ($from, $captures, $indent) = @_;
join(
$QUOTE_OUTSTANDING{$outstanding} = $QUOTED{$outstanding} = [
$name, $code, $captures
];
+ weaken($WEAK_REFS{$outstanding} = $deferred);
return $deferred;
}
sub quoted_from_sub {
my ($sub) = @_;
- $QUOTED{$sub||''};
+ $WEAK_REFS{$sub||''} and $QUOTED{$sub||''};
}
sub unquote_sub {