From: Matt S Trout Date: Wed, 12 Jan 2011 16:19:39 +0000 (+0000) Subject: add weak ref checking to Sub::Quote X-Git-Tag: release_0.009006~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a0ad775e4dc6869662f15f2c01dd6410887ee5b;p=gitmo%2FRole-Tiny.git add weak ref checking to Sub::Quote --- diff --git a/Changes b/Changes index 627b689..d43d1d3 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - weak ref checking for Sub::Quote to avoid bugs on refaddr reuse - Switch composed role names to be a valid package name 0.9.5 Tue Jan 11 2011 diff --git a/lib/Sub/Quote.pm b/lib/Sub/Quote.pm index f8087e7..337815f 100644 --- a/lib/Sub/Quote.pm +++ b/lib/Sub/Quote.pm @@ -6,6 +6,7 @@ sub _clean_eval { eval $_[0] } 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); @@ -14,6 +15,8 @@ our %QUOTE_OUTSTANDING; our %QUOTED; +our %WEAK_REFS; + sub capture_unroll { my ($from, $captures, $indent) = @_; join( @@ -117,12 +120,13 @@ sub quote_sub { $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 {