From: Vincent Pit Date: Wed, 20 Aug 2008 14:20:48 +0000 (+0200) Subject: Fix recursing into all gv's X-Git-Tag: v0.03~2 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=d7da895fc789a83e122c00e9b2df1e68159feeeb;p=perl%2Fmodules%2FB-RecDeparse.git Fix recursing into all gv's --- diff --git a/lib/B/RecDeparse.pm b/lib/B/RecDeparse.pm index 7244ec5..c1e235e 100644 --- a/lib/B/RecDeparse.pm +++ b/lib/B/RecDeparse.pm @@ -122,19 +122,20 @@ if (FOOL_SINGLE_DELIM) { sub pp_entersub { my $self = shift; - $self->{brd_sub} = 1; - my $body = $self->SUPER::pp_entersub(@_); - $self->{brd_sub} = 0; + my $body = do { + local $self->{brd_sub} = 1; + $self->SUPER::pp_entersub(@_); + }; $body =~ s/^&\s*(\w)/$1/ if $self->_recurse; return $body; } sub pp_refgen { my $self = shift; - $self->{brd_sub} = 0; - my $body = $self->SUPER::pp_refgen(@_); - $self->{brd_sub} = 1; - return $body; + return do { + local $self->{brd_sub} = 0; + $self->SUPER::pp_refgen(@_); + } } sub pp_gv { @@ -144,9 +145,10 @@ sub pp_gv { $body = $self->SUPER::pp_gv(@_); } else { my $gv = $self->gv_or_padgv($_[0]); - ++$self->{brd_cur}; - $body = 'sub ' . $self->indent($self->deparse_sub($gv->CV)); - --$self->{brd_cur}; + $body = do { + local @{$self}{qw/brd_sub brd_cur/} = (0, $self->{brd_cur} + 1); + 'sub ' . $self->indent($self->deparse_sub($gv->CV)); + }; if (FOOL_SINGLE_DELIM) { $body = $key . $body; } else { diff --git a/t/12-level.t b/t/12-level.t index a5b6163..5c1b95a 100644 --- a/t/12-level.t +++ b/t/12-level.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => (3 + 3) * 5; +use Test::More tests => (3 + 3) * 5 + 1; use B::Deparse; use B::RecDeparse; @@ -44,3 +44,7 @@ which $brd, [ ], [ qw/add mul fma/ ], 2; $brd = B::RecDeparse->new(deparse => [ $br_args ], level => 3); which $brd, [ ], [ qw/add mul fma/ ], 2; + +sub fakegv { return @_ } +eval { $brd->coderef2text(sub { return fakegv() }) }; +is($@, '', 'don\'t croak on non-CV GV\'s at level >= 1');