summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2016-07-21 14:01:17 +0100
committerDavid Mitchell <davem@iabyn.com>2016-08-03 20:54:40 +0100
commitd5994d076d5eaa2b089945b60a0ad7ea03834a5b (patch)
treee043cb4720baeceb401eed02a105681c65ff8224 /lib
parentbc304ab29c846b89ecada79bc60b7a841981bab2 (diff)
downloadperl-d5994d076d5eaa2b089945b60a0ad7ea03834a5b.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/B/Deparse.pm28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm
index 1ee584e8fb..88000dbecc 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.