#916681 Perl::Tidy: tries to access file "SCALAR(0x...)" in cwd

#916681#3
Date:
2018-12-17 10:48:03 UTC
From:
To:
The attached test program print its own tidied source.
It seems to work correctly:

   $ perl selftidy
   #!/usr/bin/perl
   use Perl::Tidy qw(perltidy);
   my $dst;
   perltidy( source => $0, destination => \$dst );
   print($dst);

But in strace output you can see a spurious filesystem access:

   $ strace -o '| grep -w SCALAR >&2' perl selftidy > /dev/null
   stat64("SCALAR(0x56bcb8a8)", 0x56bac2b0) = -1 ENOENT (No such file or directory)

I tracked it down to this code in Perl/Tidy.pm, lines 1278-1291:

        # set output file permissions
        if ( $output_file && -f $output_file && !-l $output_file ) {
            if ($input_file_permissions) {

                # give output script same permissions as input script, but
                # make it user-writable or else we can't run perltidy again.
                # Thus we retain whatever executable flags were set.
                if ( $rOpts->{'format'} eq 'tidy' ) {
                    chmod( $input_file_permissions | oct(600), $output_file );
                }

                # else use default permissions for html and any other format
            }
        }

Apparently this is run even when $output_file is a reference, not a
pathname.