Re: [COMMITTERS] pgsql: Clean up Perl code according to perlcritic

From: ilmari(at)ilmari(dot)org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=)
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [COMMITTERS] pgsql: Clean up Perl code according to perlcritic
Date: 2017-03-28 09:23:57
Message-ID: d8jvaqtvjo2.fsf@dalvik.ping.uio.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> I wrote:
>> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>>> Clean up Perl code according to perlcritic
>
>> This seems to have broken the regression tests (specifically, dblink)
>> on at least some of the Windows buildfarm critters.
>
> I'm hardly a Perl expert, but it looks to me like the culprit is this
> hunk in vcregress.pl:
>
> @@ -521,8 +521,9 @@ sub fetchRegressOpts
> # an unhandled variable reference. Ignore anything that isn't an
> # option starting with "--".
> @opts = grep {
> - s/\Q$(top_builddir)\E/\"$topdir\"/;
> - $_ !~ /\$\(/ && $_ =~ /^--/
> + my $x = $_;
> + $x =~ s/\Q$(top_builddir)\E/\"$topdir\"/;
> + $x !~ /\$\(/ && $x =~ /^--/
> } split(/\s+/, $1);
> }
> if ($m =~ /^\s*ENCODING\s*=\s*(\S+)/m)
>
> The first line in that block is actually intending to modify the value
> it's inspecting, and perlcritic's "improved" version carefully removes
> the side-effect.
>
> No doubt there are cleaner ways to do that (the comments in "man perlfunc"
> about this coding technique are not positive), but this way is not
> cleaner, it is broken.

I suggest splitting the substitution and filtering part into separate
map and grep calls, for clarity. The substituion is crying out for the
/r regex modifier to avoid the local variable, but that's only available
since perl 5.14.

diff --git a/src/tools/msvc/vcregress.pl b/src/tools/msvc/vcregress.pl
index d9367f8..cf93a60 100644
--- a/src/tools/msvc/vcregress.pl
+++ b/src/tools/msvc/vcregress.pl
@@ -520,11 +520,9 @@ sub fetchRegressOpts
# Substitute known Makefile variables, then ignore options that retain
# an unhandled variable reference. Ignore anything that isn't an
# option starting with "--".
- @opts = grep {
- my $x = $_;
- $x =~ s/\Q$(top_builddir)\E/\"$topdir\"/;
- $x !~ /\$\(/ && $x =~ /^--/
- } split(/\s+/, $1);
+ @opts = grep { !/\$\(/ && /^--/ }
+ map { (my $x = $_) =~ s/\Q$(top_builddir)\E/\"$topdir\"/; $x;}
+ split(/\s+/, $1);
}
if ($m =~ /^\s*ENCODING\s*=\s*(\S+)/m)
{

- ilmari

--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of." -- Skud's Meta-Law

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2017-03-28 11:18:27 Re: [COMMITTERS] pgsql: Clean up Perl code according to perlcritic
Previous Message Rafia Sabih 2017-03-28 03:57:11 Re: [COMMITTERS] pgsql: Improve access to parallel query from procedural languages.

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2017-03-28 09:30:03 extended stats not friendly towards ANALYZE with subset of columns
Previous Message Pavel Stehule 2017-03-28 09:14:01 xmltable doc fix and example for XMLNAMESPACES