diff options
author | David Mitchell <davem@iabyn.com> | 2022-04-13 16:09:30 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2022-04-16 18:22:13 +0100 |
commit | 55d95e1b172db3fff30c261b7b7ea9e0bca8328a (patch) | |
tree | 09423e9618764db75913195339fb0c9a354e0068 /lib/B | |
parent | 3b90549cbb135092c637895c2277a93c609640ec (diff) | |
download | perl-55d95e1b172db3fff30c261b7b7ea9e0bca8328a.tar.gz |
Deparse: skip builtin state subs
This line
use builtin qw(foo bar);
has the compile-time effect of
state sub foo { ... }
state sub bar { ... }
(except that the subs are actually aliases of &builtin::foo and ::bar).
Previously Deparse would output both the 'use builtin' line *and* the
state sub definitions. This commit suppresses the outputting of state
subs if they're in the package builtin::.
Diffstat (limited to 'lib/B')
-rw-r--r-- | lib/B/Deparse.pm | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 6e6cd3f8c9..b50608ca86 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -448,7 +448,7 @@ sub next_todo { # emit the sub. my @text; my $flags = $name->FLAGS; - push @text, + my $category = !$cv || $seq <= $name->COP_SEQ_RANGE_LOW ? $self->keyword($flags & SVpad_OUR ? "our" @@ -456,6 +456,24 @@ sub next_todo { ? "state" : "my") . " " : ""; + + # Skip lexical 'state' subs imported from the builtin:: + # package, since they are created automatically by + # use bulitin "foo" + if ($cv && $category =~ /\bstate\b/) { + my $globname; + my $gv = $cv->GV; + if ( + $gv + && defined (($globname = $gv->object_2svref)) + && $$globname =~ /^\*builtin::/ + ) { + return ''; + } + } + + push @text, $category; + # XXX We would do $self->keyword("sub"), but ‘my CORE::sub’ # doesn’t work and ‘my sub’ ignores a &sub in scope. I.e., # we have a core bug here. |