X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSub%2FQuote.pm;h=bd75a3ab9335f5550f9cff4d383fb4a61cc4bee9;hb=c600e70640098ae6ad958dc7a07187464abd37d3;hp=d9efa85888832a3c1ffea698ce811bce5b24c562;hpb=efdff87e4e45cee9e0b2bc5ac2d7659e8870c249;p=gitmo%2FMoo.git diff --git a/lib/Sub/Quote.pm b/lib/Sub/Quote.pm index d9efa85..bd75a3a 100644 --- a/lib/Sub/Quote.pm +++ b/lib/Sub/Quote.pm @@ -9,7 +9,7 @@ use B 'perlstring'; use Scalar::Util qw(weaken); use base qw(Exporter); -our $VERSION = '1.003000'; +our $VERSION = '1.003001'; $VERSION = eval $VERSION; our @EXPORT = qw(quote_sub unquote_sub quoted_from_sub); @@ -63,18 +63,18 @@ sub quote_sub { undef($captures) if $captures && !keys %$captures; my $code = pop; my $name = $_[0]; - my $deferred; - $deferred = defer_sub +($options->{no_install} ? undef : $name) => sub { - unquote_sub($deferred); + my $quoted_info; + my $deferred = defer_sub +($options->{no_install} ? undef : $name) => sub { + unquote_sub($quoted_info->[4]); }; - $QUOTED{$deferred} = [ $name, $code, $captures ]; - weaken($WEAK_REFS{$deferred} = $deferred); + $quoted_info = [ $name, $code, $captures, undef, $deferred ]; + weaken($QUOTED{$deferred} = $quoted_info); return $deferred; } sub quoted_from_sub { my ($sub) = @_; - $WEAK_REFS{$sub||''} and $QUOTED{$sub||''}; + $QUOTED{$sub||''}; } sub unquote_sub { @@ -116,11 +116,12 @@ sub unquote_sub { } sub CLONE { - %QUOTED = map { $WEAK_REFS{$_} => $QUOTED{$_} } keys %WEAK_REFS; - %WEAK_REFS = map { $_ => $_ } values %WEAK_REFS; + %QUOTED = map { defined $_ ? ($_->[4] => $_) : () } values %QUOTED; + weaken($_) for values %QUOTED; } 1; +__END__ =head1 NAME @@ -167,7 +168,10 @@ C<$name> is the subroutine where the coderef will be installed. C<$code> is a string that will be turned into code. C<\%captures> is a hashref of variables that will be made available to the -code. See the L's C for an example using captures. +code. The keys should be the full name of the variable to be made available, +including the sigil. The values should be references to the values. The +variables will contain copies of the values. See the L's +C for an example using captures. =head3 options @@ -287,3 +291,5 @@ See L for authors. =head1 COPYRIGHT AND LICENSE See L for the copyright and license. + +=cut