From: David Mitchell Date: Thu, 21 Jul 2016 13:01:17 +0000 (+0100) Subject: Deparse: move pragma deparsing into separate sub X-Git-Tag: v5.25.4~204^2~16 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/d5994d076d5eaa2b089945b60a0ad7ea03834a5b Deparse: move pragma deparsing into separate sub Currently this is done in pp_nextstate(). Move it out into a separate method called pragmata() so in the next commit it can be used elsewhere. Should be no functional changes. --- diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 1ee584e..88000db 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -1902,12 +1902,13 @@ sub _features_from_bundle { return $hh; } -# Notice how subs and formats are inserted between statements here; -# also $[ assignments and pragmas. -sub pp_nextstate { +# generate any pragmas, 'package foo' etc needed to synchronise +# with the given cop + +sub pragmata { my $self = shift; - my($op, $cx) = @_; - $self->{'curcop'} = $op; + my($op) = @_; + my @text; my $stash = $op->stashpv; @@ -1988,6 +1989,19 @@ sub pp_nextstate { $self->{'hinthash'} = $newhh; } + return join("", @text); +} + + +# Notice how subs and formats are inserted between statements here; +# also $[ assignments and pragmas. +sub pp_nextstate { + my $self = shift; + my($op, $cx) = @_; + $self->{'curcop'} = $op; + + my @text = $self->pragmata($op); + my @subs = $self->cop_subs($op); if (@subs) { # Special marker to swallow up the semicolon @@ -1995,14 +2009,14 @@ sub pp_nextstate { } push @text, @subs; + # cop_subs above may have changed the package; restore it - $stash = $op->stashpv; + my $stash = $op->stashpv; if ($stash ne $self->{'curstash'}) { push @text, $self->keyword("package") . " $stash;\n"; $self->{'curstash'} = $stash; } - # This should go after of any branches that add statements, to # increase the chances that it refers to the same line it did in # the original program.