diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/B/Deparse.pm | 8 | ||||
-rw-r--r-- | lib/B/Deparse.t | 40 |
2 files changed, 44 insertions, 4 deletions
diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index adfd9f3251..284da0f9cf 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -1625,11 +1625,13 @@ sub find_scope { sub cop_subs { my ($self, $op, $out_seq) = @_; my $seq = $op->cop_seq; - # If we have nephews, then our sequence number indicates - # the cop_seq of the end of some sort of scope. - if (class($op->sibling) ne "NULL" && $op->sibling->flags & OPf_KIDS + if ($] < 5.021006) { + # If we have nephews, then our sequence number indicates + # the cop_seq of the end of some sort of scope. + if (class($op->sibling) ne "NULL" && $op->sibling->flags & OPf_KIDS and my $nseq = $self->find_scope_st($op->sibling) ) { $seq = $nseq; + } } $seq = $out_seq if defined($out_seq) && $out_seq < $seq; return $self->seq_subs($seq); diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t index cd3b828195..6b2799e46e 100644 --- a/lib/B/Deparse.t +++ b/lib/B/Deparse.t @@ -13,7 +13,7 @@ use warnings; use strict; use Test::More; -my $tests = 26; # not counting those in the __DATA__ section +my $tests = 27; # not counting those in the __DATA__ section use B::Deparse; my $deparse = B::Deparse->new(); @@ -327,6 +327,44 @@ like($a, qr/my sub __DATA__;\n\(\);\nCORE::__DATA__/, $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`; like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations'); +# BEGIN blocks +SKIP : { + skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006; + my $prog = ' + BEGIN { pop } + { + BEGIN { pop } + { + no overloading; + { + BEGIN { pop } + die + } + } + }'; + $prog =~ s/\n//g; + $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`; + $a =~ s/-e syntax OK\n//g; + is($a, <<'EOCODJ', 'BEGIN blocks'); +sub BEGIN { + pop @ARGV; +} +{ + sub BEGIN { + pop @ARGV; + } + { + no overloading; + { + sub BEGIN { + pop @ARGV; + } + die; + } + } +} +EOCODJ +} done_testing($tests); |