This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
put package declaration before label in deparsing
authorZefram <zefram@fysh.org>
Thu, 29 Apr 2010 23:02:06 +0000 (00:02 +0100)
committerDavid Golden <dagolden@cpan.org>
Thu, 29 Apr 2010 23:41:10 +0000 (19:41 -0400)
When deparsing a nextstate op that has both a change of package (relative
to the previous nextstate) and a label, the package declaration must be
emitted first, because it is syntactically impermissible for a label to
prefix a package declaration.

dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t

index 89bc28d..fc0125d 100644 (file)
@@ -23,7 +23,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
         PMf_MULTILINE PMf_SINGLELINE PMf_FOLD PMf_EXTENDED),
         ($] < 5.009 ? 'PMf_SKIPWHITE' : 'RXf_SKIPWHITE'),
         ($] < 5.011 ? 'CVf_LOCKED' : ());
         PMf_MULTILINE PMf_SINGLELINE PMf_FOLD PMf_EXTENDED),
         ($] < 5.009 ? 'PMf_SKIPWHITE' : 'RXf_SKIPWHITE'),
         ($] < 5.011 ? 'CVf_LOCKED' : ());
-$VERSION = 0.96;
+$VERSION = 0.97;
 use strict;
 use vars qw/$AUTOLOAD/;
 use warnings ();
 use strict;
 use vars qw/$AUTOLOAD/;
 use warnings ();
@@ -1380,7 +1380,6 @@ sub pp_nextstate {
     $self->{'curcop'} = $op;
     my @text;
     push @text, $self->cop_subs($op);
     $self->{'curcop'} = $op;
     my @text;
     push @text, $self->cop_subs($op);
-    push @text, $op->label . ": " if $op->label;
     my $stash = $op->stashpv;
     if ($stash ne $self->{'curstash'}) {
        push @text, "package $stash;\n";
     my $stash = $op->stashpv;
     if ($stash ne $self->{'curstash'}) {
        push @text, "package $stash;\n";
@@ -1434,6 +1433,8 @@ sub pp_nextstate {
          ' "' . $op->file, qq'"\n';
     }
 
          ' "' . $op->file, qq'"\n';
     }
 
+    push @text, $op->label . ": " if $op->label;
+
     return join("", @text);
 }
 
     return join("", @text);
 }
 
index 331766b..e3c62ba 100644 (file)
@@ -17,7 +17,7 @@ BEGIN {
     require feature;
     feature->import(':5.10');
 }
     require feature;
     feature->import(':5.10');
 }
-use Test::More tests => 84;
+use Test::More tests => 85;
 use Config ();
 
 use B::Deparse;
 use Config ();
 
 use B::Deparse;
@@ -628,3 +628,8 @@ my($r, $s, @a);
 $r = qr/foo/;
 @a = split(/$r/, $s, 0);
 ();
 $r = qr/foo/;
 @a = split(/$r/, $s, 0);
 ();
+####
+{
+    package Foo;
+    label: print 123;
+}