From: Noah Misch <noah@leadboat.com>
To: Andrew Dunstan <andrew@dunslane.net>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andres Freund <andres@anarazel.de>
Cc: Erik Rijkers <er@xs4all.nl>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Mark Dilger <mark.dilger@enterprisedb.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Postgres perl module namespace
Date: Wed, 22 Jun 2022 00:21:44 -0700
Message-ID: <20220622072144.GD4167527@rfd.leadboat.com> (raw)
In-Reply-To: <6790e47f-aa12-e28b-e123-3fbe46f78513@dunslane.net>
References: <20220418141530.nfxtkohefvwnzncl@alap3.anarazel.de>
<20220418155224.GA1149931@rfd.leadboat.com>
<d74da58b-cfee-4fea-a31a-439921c0feb0@dunslane.net>
<2361941.1650303832@sss.pgh.pa.us>
<02188900-ba1e-8c6c-c7dd-98294f39c23f@dunslane.net>
<2364418.1650305263@sss.pgh.pa.us>
<f0d10209-7921-365a-aa7d-066e8cb8062e@dunslane.net>
<03909eb8-21ce-ca68-fea0-cd338e35ad59@dunslane.net>
<Yl86JyFPzbZQXmYa@paquier.xyz>
<6790e47f-aa12-e28b-e123-3fbe46f78513@dunslane.net>
On Tue, Apr 19, 2022 at 07:24:58PM -0400, Andrew Dunstan wrote:
> On 2022-04-19 Tu 18:39, Michael Paquier wrote:
> > +*generate_ascii_string = *TestLib::generate_ascii_string;
> > +*slurp_dir = *TestLib::slurp_dir;
> > +*slurp_file = *TestLib::slurp_file;
> >
> > I am not sure if it is possible and my perl-fu is limited in this
> > area, but could a failure be enforced when loading this path if a new
> > routine added in TestLib.pm is forgotten in this list?
>
> Not very easily that I'm aware of, but maybe some superior perl wizard
> will know better.
One can alias the symbol table, like https://metacpan.org/pod/Package::Alias
does. I'm attaching what I plan to use. Today, check-world fails after
sed -i 's/TestLib/PostgreSQL::Test::Utils/g; s/PostgresNode/PostgreSQL::Test::Cluster/g' **/*.pl
on REL_14_STABLE, because today's alias list is incomplete. With this change,
the same check-world passes.
Author: Noah Misch <noah@leadboat.com>
Commit: Noah Misch <noah@leadboat.com>
For PostgreSQL::Test compatibility, alias entire package symbol tables.
Remove the need to edit back-branch-specific code sites when
back-patching the addition of a PostgreSQL::Test::Utils symbol. Replace
per-symbol, incomplete alias lists. Give old and new package names the
same EXPORT and EXPORT_OK semantics. Back-patch to v10 (all supported
versions).
Reviewed by FIXME.
Discussion: https://postgr.es/m/FIXMEdiff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pmindex 12339c2..a855fbc 100644--- a/src/test/perl/PostgreSQL/Test/Cluster.pm+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm@@ -1,9 +1,9 @@
# Copyright (c) 2022, PostgreSQL Global Development Group
-# allow use of release 15+ perl namespace in older branches-# just 'use' the older module name.-# See PostgresNode.pm for function implementations+# Allow use of release 15+ Perl package name in older branches, by giving that+# package the same symbol table as the older package. See PostgresNode::new+# for behavior reacting to the class name.
package PostgreSQL::Test::Cluster;
@@ -11,5 +11,8 @@ use strict;
use warnings;
use PostgresNode;
+BEGIN { *PostgreSQL::Test::Cluster:: = \*PostgresNode::; }++use Exporter 'import';
1;
diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pmindex bdbbd6e..e743bdf 100644--- a/src/test/perl/PostgreSQL/Test/Utils.pm+++ b/src/test/perl/PostgreSQL/Test/Utils.pm@@ -1,48 +1,16 @@
# Copyright (c) 2022, PostgreSQL Global Development Group
-# allow use of release 15+ perl namespace in older branches-# just 'use' the older module name.-# We export the same names as the v15 module.-# See TestLib.pm for alias assignment that makes this all work.+# Allow use of release 15+ Perl package name in older branches, by giving that+# package the same symbol table as the older package.
package PostgreSQL::Test::Utils;
use strict;
use warnings;
-use Exporter 'import';-
use TestLib;
+BEGIN { *PostgreSQL::Test::Utils:: = \*TestLib::; }-our @EXPORT = qw(- generate_ascii_string- slurp_dir- slurp_file- append_to_file- check_mode_recursive- chmod_recursive- check_pg_config- dir_symlink- system_or_bail- system_log- run_log- run_command- pump_until-- command_ok- command_fails- command_exit_is- program_help_ok- program_version_ok- program_options_handling_ok- command_like- command_like_safe- command_fails_like- command_checks_all-- $windows_os- $is_msys2- $use_unix_sockets-);+use Exporter 'import';
1;
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pmindex be90963..5b8c7a9 100644--- a/src/test/perl/PostgresNode.pm+++ b/src/test/perl/PostgresNode.pm@@ -149,6 +149,11 @@ of finding port numbers, registering instances for cleanup, etc.
sub new
{
my ($class, $name, $pghost, $pgport) = @_;
++ # Use release 15+ semantics when called under a release 15+ name.+ return PostgresNode->get_new_node(@_[ 1 .. $#_ ])+ if $class ne 'PostgresNode';+
my $testname = basename($0);
$testname =~ s/\.[^.]+$//;
my $self = {
@@ -2796,18 +2801,4 @@ sub corrupt_page_checksum
=cut
-# support release 15+ perl module namespace--package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)--sub new-{- shift; # remove class param from args- return PostgresNode->get_new_node(@_);-}--no warnings 'once';--*get_free_port = *PostgresNode::get_free_port;-
1;
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pmindex f3ee20a..610050e 100644--- a/src/test/perl/TestLib.pm+++ b/src/test/perl/TestLib.pm@@ -979,46 +979,4 @@ sub command_checks_all
=cut
-# support release 15+ perl module namespace--package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)--# we don't want to export anything here, but we want to support things called-# via this package name explicitly.--# use typeglobs to alias these functions and variables--no warnings qw(once);--*generate_ascii_string = *TestLib::generate_ascii_string;-*slurp_dir = *TestLib::slurp_dir;-*slurp_file = *TestLib::slurp_file;-*append_to_file = *TestLib::append_to_file;-*check_mode_recursive = *TestLib::check_mode_recursive;-*chmod_recursive = *TestLib::chmod_recursive;-*check_pg_config = *TestLib::check_pg_config;-*dir_symlink = *TestLib::dir_symlink;-*system_or_bail = *TestLib::system_or_bail;-*system_log = *TestLib::system_log;-*run_log = *TestLib::run_log;-*run_command = *TestLib::run_command;-*command_ok = *TestLib::command_ok;-*command_fails = *TestLib::command_fails;-*command_exit_is = *TestLib::command_exit_is;-*program_help_ok = *TestLib::program_help_ok;-*program_version_ok = *TestLib::program_version_ok;-*program_options_handling_ok = *TestLib::program_options_handling_ok;-*command_like = *TestLib::command_like;-*command_like_safe = *TestLib::command_like_safe;-*command_fails_like = *TestLib::command_fails_like;-*command_checks_all = *TestLib::command_checks_all;--*windows_os = *TestLib::windows_os;-*is_msys2 = *TestLib::is_msys2;-*use_unix_sockets = *TestLib::use_unix_sockets;-*timeout_default = *TestLib::timeout_default;-*tmp_check = *TestLib::tmp_check;-*log_path = *TestLib::log_path;-*test_logfile = *TestLib::test_log_file;-
1;
Attachments:
[text/plain] alias-perl-symbol-tables-v1.patch (5.3K, ../20220622072144.GD4167527@rfd.leadboat.com/2-alias-perl-symbol-tables-v1.patch)
download | inline diff:
Author: Noah Misch <noah@leadboat.com>
Commit: Noah Misch <noah@leadboat.com>
For PostgreSQL::Test compatibility, alias entire package symbol tables.
Remove the need to edit back-branch-specific code sites when
back-patching the addition of a PostgreSQL::Test::Utils symbol. Replace
per-symbol, incomplete alias lists. Give old and new package names the
same EXPORT and EXPORT_OK semantics. Back-patch to v10 (all supported
versions).
Reviewed by FIXME.
Discussion: https://postgr.es/m/FIXME
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pmindex 12339c2..a855fbc 100644--- a/src/test/perl/PostgreSQL/Test/Cluster.pm+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm@@ -1,9 +1,9 @@
# Copyright (c) 2022, PostgreSQL Global Development Group
-# allow use of release 15+ perl namespace in older branches-# just 'use' the older module name.-# See PostgresNode.pm for function implementations+# Allow use of release 15+ Perl package name in older branches, by giving that+# package the same symbol table as the older package. See PostgresNode::new+# for behavior reacting to the class name.
package PostgreSQL::Test::Cluster;
@@ -11,5 +11,8 @@ use strict;
use warnings;
use PostgresNode;
+BEGIN { *PostgreSQL::Test::Cluster:: = \*PostgresNode::; }++use Exporter 'import';
1;
diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pmindex bdbbd6e..e743bdf 100644--- a/src/test/perl/PostgreSQL/Test/Utils.pm+++ b/src/test/perl/PostgreSQL/Test/Utils.pm@@ -1,48 +1,16 @@
# Copyright (c) 2022, PostgreSQL Global Development Group
-# allow use of release 15+ perl namespace in older branches-# just 'use' the older module name.-# We export the same names as the v15 module.-# See TestLib.pm for alias assignment that makes this all work.+# Allow use of release 15+ Perl package name in older branches, by giving that+# package the same symbol table as the older package.
package PostgreSQL::Test::Utils;
use strict;
use warnings;
-use Exporter 'import';-
use TestLib;
+BEGIN { *PostgreSQL::Test::Utils:: = \*TestLib::; }-our @EXPORT = qw(- generate_ascii_string- slurp_dir- slurp_file- append_to_file- check_mode_recursive- chmod_recursive- check_pg_config- dir_symlink- system_or_bail- system_log- run_log- run_command- pump_until-- command_ok- command_fails- command_exit_is- program_help_ok- program_version_ok- program_options_handling_ok- command_like- command_like_safe- command_fails_like- command_checks_all-- $windows_os- $is_msys2- $use_unix_sockets-);+use Exporter 'import';
1;
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pmindex be90963..5b8c7a9 100644--- a/src/test/perl/PostgresNode.pm+++ b/src/test/perl/PostgresNode.pm@@ -149,6 +149,11 @@ of finding port numbers, registering instances for cleanup, etc.
sub new
{
my ($class, $name, $pghost, $pgport) = @_;
++ # Use release 15+ semantics when called under a release 15+ name.+ return PostgresNode->get_new_node(@_[ 1 .. $#_ ])+ if $class ne 'PostgresNode';+
my $testname = basename($0);
$testname =~ s/\.[^.]+$//;
my $self = {
@@ -2796,18 +2801,4 @@ sub corrupt_page_checksum
=cut
-# support release 15+ perl module namespace--package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)--sub new-{- shift; # remove class param from args- return PostgresNode->get_new_node(@_);-}--no warnings 'once';--*get_free_port = *PostgresNode::get_free_port;-
1;
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pmindex f3ee20a..610050e 100644--- a/src/test/perl/TestLib.pm+++ b/src/test/perl/TestLib.pm@@ -979,46 +979,4 @@ sub command_checks_all
=cut
-# support release 15+ perl module namespace--package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)--# we don't want to export anything here, but we want to support things called-# via this package name explicitly.--# use typeglobs to alias these functions and variables--no warnings qw(once);--*generate_ascii_string = *TestLib::generate_ascii_string;-*slurp_dir = *TestLib::slurp_dir;-*slurp_file = *TestLib::slurp_file;-*append_to_file = *TestLib::append_to_file;-*check_mode_recursive = *TestLib::check_mode_recursive;-*chmod_recursive = *TestLib::chmod_recursive;-*check_pg_config = *TestLib::check_pg_config;-*dir_symlink = *TestLib::dir_symlink;-*system_or_bail = *TestLib::system_or_bail;-*system_log = *TestLib::system_log;-*run_log = *TestLib::run_log;-*run_command = *TestLib::run_command;-*command_ok = *TestLib::command_ok;-*command_fails = *TestLib::command_fails;-*command_exit_is = *TestLib::command_exit_is;-*program_help_ok = *TestLib::program_help_ok;-*program_version_ok = *TestLib::program_version_ok;-*program_options_handling_ok = *TestLib::program_options_handling_ok;-*command_like = *TestLib::command_like;-*command_like_safe = *TestLib::command_like_safe;-*command_fails_like = *TestLib::command_fails_like;-*command_checks_all = *TestLib::command_checks_all;--*windows_os = *TestLib::windows_os;-*is_msys2 = *TestLib::is_msys2;-*use_unix_sockets = *TestLib::use_unix_sockets;-*timeout_default = *TestLib::timeout_default;-*tmp_check = *TestLib::tmp_check;-*log_path = *TestLib::log_path;-*test_logfile = *TestLib::test_log_file;-
1;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: noah@leadboat.com, andrew@dunslane.net, michael@paquier.xyz, tgl@sss.pgh.pa.us, andres@anarazel.de, er@xs4all.nl, robertmhaas@gmail.com, alvherre@alvh.no-ip.org, mark.dilger@enterprisedb.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Postgres perl module namespace
In-Reply-To: <20220622072144.GD4167527@rfd.leadboat.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox