sub config_vars {
foreach (@_) {
- if (/\W/) {
- my @matches = config_re($_);
- print map "$_\n", @matches ? @matches : "$_: not found";
+ my ($notag,$qry,$lncont) = m/^(:)?(.*?)(:)?$/; # flags fore and aft,
+ my $prfx = $notag ? '': "$qry="; # prefix for print
+ my $lnend = $lncont ? ' ' : ";\n"; # ending for print
+
+ if ($qry =~ /\W/) {
+ my @matches = config_re($qry);
+ print map "$_$lnend", @matches ? @matches : "$qry: not found" if !$notag;
+ print map { s/\w+=//; "$_$lnend" } @matches ? @matches : "$qry: not found" if $notag;
} else {
- my $v = (exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
+ my $v = (exists $Config{$qry}) ? $Config{$qry} : 'UNKNOWN';
$v = 'undef' unless defined $v;
- print "$_='$v';\n";
+ print "${prfx}'${v}'$lnend";
}
}
}
require "./test.pl";
}
-plan tests => 36;
+plan tests => 46;
use_ok('Config');
my $out2 = $$out;
$out->clear;
-untie *STDOUT;
+Config::config_vars('PERL_API_.*');
+my $out3 = $$out;
+$out->clear;
+
+Config::config_vars(':PERL_API_.*:');
+my $out4 = $$out;
+$out->clear;
+Config::config_vars(':PERL_API_REVISION:');
+my $out5 = $$out;
+$out->clear;
+
+untie *STDOUT;
like($out1, qr/^cc='\Q$Config{cc}\E';/, "config_vars cc");
like($out2, qr/^d_bork='UNKNOWN';/, "config_vars d_bork is UNKNOWN");
+is(3, scalar split(/\n/, $out3), "3 PERL_API vars found");
+my @api = $out3 =~ /^PERL_API_(\w+)=(.*);/mg;
+is("'5'", $api[1], "1st is 5");
+is("'9'", $api[5], "2nd is 9");
+is("'1'", $api[3], "3rd is 1");
+@api = split(/ /, $out4);
+is(3, @api, "trailing colon puts 3 terms on same line");
+unlike($out4, qr/=/, "leading colon suppresses param names");
+is("'5'", $api[0], "revision is 5");
+is("'9'", $api[2], "version is 9");
+is("'1'", $api[1], "subversion is 1");
+
+is("'5' ", $out5, "leading and trailing colons return just the value");
# Read-only.
undef $@;
=item B<-V:>I<name>
-Prints to STDOUT the value of the named configuration variable.
+Prints to STDOUT the value of the named configuration variable(s),
+with multiples when your query looks like a regex.
For example,
- $ perl -V:man.dir
-
-will provide strong clues about what your MANPATH variable should
-be set to in order to access the Perl documentation.
+ $ perl -V:lib.
+ libs='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc';
+ libc='/lib/libc-2.2.4.so';
+ $ perl -V:lib.*
+ libpth='/usr/local/lib /lib /usr/lib';
+ libs='-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc';
+ lib_ext='.a';
+ libc='/lib/libc-2.2.4.so';
+ libperl='libperl.a';
+ ....
+
+Additionally, extra colons can be used to control formatting. A
+trailing colon suppresses the linefeed and terminator ';', allowing
+you to embed queries into shell commands. (mnemonic: PATH separator
+':'.)
+
+ $ echo "compression-vars: " `perl -V:z.*: ` " are here !"
+ compression-vars: zcat='' zip='zip' are here !
+
+A leading colon removes the 'name=' part of the response, this allows
+you to map to the name you need.
+
+ $ echo "goodvfork="`./perl -Ilib -V::usevfork`
+ goodvfork=false;
+
+Leading and trailing colons can be used together if you need
+positional parameter values without the names. Note that in the case
+below, the PERL_API params are returned in alphabetical order.
+
+ $ echo building_on `perl -V::osname: -V::PERL_API_.*:` now
+ building_on 'linux' '5' '1' '9' now
=item B<-w>