From: Jim Cromie Date: Tue, 11 May 2004 00:15:46 +0000 (-0600) Subject: various -V: searches [PATCH] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4a305f6a9139c383ac61b8e258cf614236af6a28;p=p5sagit%2Fp5-mst-13.2.git various -V: searches [PATCH] Message-ID: <40A06F92.1070607@divsol.com> p4raw-id: //depot/perl@22810 --- diff --git a/configpm b/configpm index d3d15ee..4f301c3 100755 --- a/configpm +++ b/configpm @@ -334,13 +334,18 @@ sub config_re { 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"; } } } diff --git a/lib/Config.t b/lib/Config.t index 6e4b47c..c32571c 100644 --- a/lib/Config.t +++ b/lib/Config.t @@ -6,7 +6,7 @@ BEGIN { require "./test.pl"; } -plan tests => 36; +plan tests => 46; use_ok('Config'); @@ -77,11 +77,35 @@ Config::config_vars('d_bork'); 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 $@; diff --git a/pod/perlrun.pod b/pod/perlrun.pod index a6b90da..b386498 100644 --- a/pod/perlrun.pod +++ b/pod/perlrun.pod @@ -829,13 +829,41 @@ values of @INC. =item B<-V:>I -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>