Deparse.pm: More functions that do not follow llafr
authorFather Chrysostomos <sprout@cpan.org>
Thu, 8 Dec 2011 06:40:28 +0000 (22:40 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 8 Dec 2011 14:18:09 +0000 (06:18 -0800)
See the previous commit.

Again, whether we apply the llafr to loop exits shouldn’t be about
whether parentheses look nice, but whether the final code parses
correctly.

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

index 7731e2a..ab46e7a 100644 (file)
@@ -1877,9 +1877,13 @@ sub pp_require {
        my $name = $self->const_sv($op->first)->PV;
        $name =~ s[/][::]g;
        $name =~ s/\.pm//g;
-       return "$opname $name";
+       return $self->maybe_parens("$opname $name", $cx, 16);
     } else {   
-       $self->unop($op, $cx, $op->first->private & OPpCONST_NOVER ? "no" : $opname);
+       $self->unop(
+           $op, $cx,
+           $op->first->private & OPpCONST_NOVER ? "no" : $opname,
+           1, # llafr does not apply
+       );
     }
 }
 
@@ -2009,14 +2013,14 @@ sub loopex {
     my $self = shift;
     my ($op, $cx, $name) = @_;
     if (class($op) eq "PVOP") {
-       return "$name " . $op->pv;
+       $name .= " " . $op->pv;
     } elsif (class($op) eq "OP") {
-       return $name;
+       # no-op
     } elsif (class($op) eq "UNOP") {
-       # Note -- loop exits are actually exempt from the
-       # looks-like-a-func rule, but a few extra parens won't hurt
-       return $self->maybe_parens_unop($name, $op->first, $cx);
+       (my $kid = $self->deparse($op->first, 16)) =~ s/^\cS//;
+       $name .= " $kid";
     }
+    return $self->maybe_parens($name, $cx, 16);
 }
 
 sub pp_last { loopex(@_, "last") }
index badf0da..2361088 100644 (file)
@@ -843,3 +843,10 @@ do({});
 () = (do 'file') + time;
 () = (do ($1 + $2) * $3) + time;
 () = (do ($1 xor $2)) + time;
+() = (goto 1) + 3;
+() = (require 'foo') + 3;
+() = (require foo) + 3;
+() = (dump 1) + 3;
+() = (last 1) + 3;
+() = (next 1) + 3;
+() = (redo 1) + 3;