Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita688c39

Browse files
committed
Make PostgreSQL::Test::Cluster::config_data more flexible
Currently this only allows for one argument, which must be present, andalways returns a single string. With this change the following now allwork: $all_config = $node->config_data; %config_map = ($node->config_data); $incdir = $node->config_data('--include-dir'); ($incdir, $sharedir) = $node->config_data( qw(--include-dir --share-dir));Backpatch to release 15 where this was introduced.Discussion:https://postgr.es/m/73eea68e-3b6f-5f63-6024-25ed26b52016@dunslane.netReviewed by Tom Lane, Alvaro Herrera, Michael Paquier.
1 parentc727f51 commita688c39

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

‎src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ PostgreSQL::Test::Cluster - class representing PostgreSQL server instance
2626
# Modify or delete an existing setting
2727
$node->adjust_conf('postgresql.conf', 'max_wal_senders', '10');
2828
29+
# get pg_config settings
30+
# all the settings in one string
31+
$pgconfig = $node->config_data;
32+
# all the settings as a map
33+
%config_map = ($node->config_data);
34+
# specified settings
35+
($incdir, $sharedir) = $node->config_data(qw(--includedir --sharedir));
36+
2937
# run a query with psql, like:
3038
# echo 'SELECT 1' | psql -qAXt postgres -v ON_ERROR_STOP=1
3139
$psql_stdout = $node->safe_psql('postgres', 'SELECT 1');
@@ -345,27 +353,46 @@ sub pg_version
345353

346354
=pod
347355
348-
=item$node->config_data($option)
356+
=item$node->config_data( option ...)
357+
358+
Return configuration data from pg_config, using options (if supplied).
359+
The options will be things like '--sharedir'.
349360
350-
Return a string holding configuration data from pg_config, with $option
351-
being the option switch used with the pg_config command.
361+
If no options are supplied, return a string in scalar context or a map in
362+
array context.
363+
364+
If options are supplied, return the list of values.
352365
353366
=cut
354367

355368
subconfig_data
356369
{
357-
my ($self,$option) =@_;
370+
my ($self,@options) =@_;
358371
local%ENV =$self->_get_env();
359372

360373
my ($stdout,$stderr);
361374
my$result =
362-
IPC::Run::run [$self->installed_command('pg_config'),$option ],
375+
IPC::Run::run [$self->installed_command('pg_config'),@options ],
363376
'>', \$stdout,'2>', \$stderr
364377
ordie"could not execute pg_config";
378+
# standardize line endings
379+
$stdout =~s/\r(?=\n)//g;
380+
# no options, scalar context: just hand back the output
381+
return$stdoutunless (wantarray ||@options);
365382
chomp($stdout);
366-
$stdout =~s/\r$//;
367-
368-
return$stdout;
383+
# exactly one option: hand back the output (minus LF)
384+
return$stdoutif (@options == 1);
385+
my@lines =split(/\n/,$stdout);
386+
# more than one option: hand back the list of values;
387+
return@linesif (@options);
388+
# no options, array context: return a map
389+
my@map;
390+
foreachmy$line (@lines)
391+
{
392+
my ($k,$v) =split (/ =/,$line,2);
393+
push(@map,$k,$v);
394+
}
395+
return@map;
369396
}
370397

371398
=pod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp