Deparse filetest ops without llafr
authorFather Chrysostomos <sprout@cpan.org>
Thu, 8 Dec 2011 17:30:31 +0000 (09:30 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 8 Dec 2011 17:32:37 +0000 (09:32 -0800)
Before this commit, (-e $_) + 72 deparsed incorrectly, because it
became -e($_) + 72, equivalent to -e ($_+72).

Concerning the removed comment, it’s more important to produce correct
code than nice-looking code.

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

index 2ca91f6..f400ed7 100644 (file)
@@ -2034,7 +2034,11 @@ sub ftst {
     my($op, $cx, $name) = @_;
     if (class($op) eq "UNOP") {
        # Genuine '-X' filetests are exempt from the LLAFR, but not
-       # l?stat(); for the sake of clarity, give'em all parens
+       # l?stat()
+       if ($name =~ /^-/) {
+           (my $kid = $self->deparse($op->first, 16)) =~ s/^\cS//;
+           return $self->maybe_parens("$name $kid", $cx, 16);
+       }
        return $self->maybe_parens_unop($name, $op->first, $cx);
     } elsif (class($op) =~ /^(SV|PAD)OP$/) {
        return $self->maybe_parens_func($name, $self->pp_gv($op, 1), $cx, 16);
index de7b764..820a5ef 100644 (file)
@@ -862,3 +862,9 @@ CORE::do({});
 () = (last 1) + 3;
 () = (next 1) + 3;
 () = (redo 1) + 3;
+() = (-R $_) + 3;
+() = (-W $_) + 3;
+() = (-X $_) + 3;
+() = (-r $_) + 3;
+() = (-w $_) + 3;
+() = (-x $_) + 3;