Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3879040

Browse files
committed
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 Andrew Dunstan. Discussion: https://postgr.es/m/[email protected]
1 parent d873b5a commit 3879040

File tree

4 files changed

+21
-77
lines changed

4 files changed

+21
-77
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11

22
# Copyright (c) 2022, PostgreSQL Global Development Group
33

4-
# allow use of release 15+ perl namespace in older branches
5-
# just 'use' the older module name.
6-
# See PostgresNode.pm for function implementations
4+
# Allow use of release 15+ Perl package name in older branches, by giving that
5+
# package the same symbol table as the older package. See PostgresNode::new
6+
# for supporting heuristics.
77

88
package PostgreSQL::Test::Cluster;
99

1010
use strict;
1111
use warnings;
1212

1313
use PostgresNode;
14+
BEGIN { *PostgreSQL::Test::Cluster:: = \*PostgresNode::; }
15+
16+
use Exporter 'import';
1417

1518
1;
Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,16 @@
11
# Copyright (c) 2022, PostgreSQL Global Development Group
22

3-
# allow use of release 15+ perl namespace in older branches
4-
# just 'use' the older module name.
5-
# We export the same names as the v15 module.
6-
# See TestLib.pm for alias assignment that makes this all work.
3+
# Allow use of release 15+ Perl package name in older branches, by giving that
4+
# package the same symbol table as the older package.
75

86
package PostgreSQL::Test::Utils;
97

108
use strict;
119
use warnings;
1210

13-
use Exporter 'import';
14-
1511
use TestLib;
12+
BEGIN { *PostgreSQL::Test::Utils:: = \*TestLib::; }
1613

17-
our @EXPORT = qw(
18-
generate_ascii_string
19-
slurp_dir
20-
slurp_file
21-
append_to_file
22-
system_or_bail
23-
system_log
24-
run_log
25-
pump_until
26-
27-
command_ok
28-
command_fails
29-
command_exit_is
30-
program_help_ok
31-
program_version_ok
32-
program_options_handling_ok
33-
command_like
34-
command_like_safe
35-
command_fails_like
36-
command_checks_all
37-
38-
$windows_os
39-
);
14+
use Exporter 'import';
4015

4116
1;

src/test/perl/PostgresNode.pm

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ of finding port numbers, registering instances for cleanup, etc.
147147
sub new
148148
{
149149
my ($class, $name, $pghost, $pgport) = @_;
150+
151+
# Use release 15+ semantics when the arguments look like (node_name,
152+
# %params). We can't use $class to decide, because get_new_node() passes
153+
# a v14- argument list regardless of the class. $class might be an
154+
# out-of-core subclass. $class->isa('PostgresNode') returns true even for
155+
# descendants of PostgreSQL::Test::Cluster, so it doesn't help.
156+
return $class->get_new_node(@_[ 1 .. $#_ ])
157+
if !$pghost
158+
or !$pgport
159+
or $pghost =~ /^[a-zA-Z0-9_]$/;
160+
150161
my $testname = basename($0);
151162
$testname =~ s/\.[^.]+$//;
152163
my $self = {
@@ -2134,14 +2145,4 @@ sub pg_recvlogical_upto
21342145
21352146
=cut
21362147

2137-
# support release 15+ perl module namespace
2138-
2139-
package PostgreSQL::Test::Cluster; ## no critic (ProhibitMultiplePackages)
2140-
2141-
sub new
2142-
{
2143-
shift; # remove class param from args
2144-
return PostgresNode->get_new_node(@_);
2145-
}
2146-
21472148
1;

src/test/perl/TestLib.pm

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -485,39 +485,4 @@ sub command_checks_all
485485
return;
486486
}
487487

488-
# support release 15+ perl module namespace
489-
490-
package PostgreSQL::Test::Utils; ## no critic (ProhibitMultiplePackages)
491-
492-
# we don't want to export anything here, but we want to support things called
493-
# via this package name explicitly.
494-
495-
# use typeglobs to alias these functions and variables
496-
497-
no warnings qw(once);
498-
499-
*generate_ascii_string = *TestLib::generate_ascii_string;
500-
*slurp_dir = *TestLib::slurp_dir;
501-
*slurp_file = *TestLib::slurp_file;
502-
*append_to_file = *TestLib::append_to_file;
503-
*system_or_bail = *TestLib::system_or_bail;
504-
*system_log = *TestLib::system_log;
505-
*run_log = *TestLib::run_log;
506-
*command_ok = *TestLib::command_ok;
507-
*command_fails = *TestLib::command_fails;
508-
*command_exit_is = *TestLib::command_exit_is;
509-
*program_help_ok = *TestLib::program_help_ok;
510-
*program_version_ok = *TestLib::program_version_ok;
511-
*program_options_handling_ok = *TestLib::program_options_handling_ok;
512-
*command_like = *TestLib::command_like;
513-
*command_like_safe = *TestLib::command_like_safe;
514-
*command_fails_like = *TestLib::command_fails_like;
515-
*command_checks_all = *TestLib::command_checks_all;
516-
517-
*windows_os = *TestLib::windows_os;
518-
*timeout_default = *TestLib::timeout_default;
519-
*tmp_check = *TestLib::tmp_check;
520-
*log_path = *TestLib::log_path;
521-
*test_logfile = *TestLib::test_log_file;
522-
523488
1;

0 commit comments

Comments
 (0)