]> mj.ucw.cz Git - libucw.git/blobdiff - lib/perl/Config.pm
Merge with git+ssh://cvs.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / perl / Config.pm
index 6e59ca073b598cf1d71e21f1f5eb4f4e93c4a7af..aa62b9a90081ba06ea36f4040598271415307252 100644 (file)
@@ -1,5 +1,9 @@
-# Perl module for parsing Sherlock configuration files (using the config utility)
-# (c) 2002 Martin Mares <mj@ucw.cz>
+#      Perl module for parsing Sherlock configuration files (using the config utility)
+#
+#      (c) 2002--2005 Martin Mares <mj@ucw.cz>
+#
+#      This software may be freely distributed and used according to the terms
+#      of the GNU Lesser General Public License.
 
 package Sherlock::Config;
 
@@ -17,18 +21,20 @@ sub Parse(@) {
        my $override_config = 0;
        push @options, "config|C=s" => sub { my ($o,$a)=@_; $defargs .= " -C'$a'"; $override_config=1; };
        push @options, "set|S=s" => sub { my ($o,$a)=@_; $defargs .= " -S'$a'"; };
+       Getopt::Long::Configure("bundling");
        Getopt::Long::GetOptions(@options) or return 0;
        if (!$override_config && $DefaultConfigFile) {
                $defargs = "-C'$DefaultConfigFile' $defargs";
        }
        foreach my $section (keys %Sections) {
                my $opts = $Sections{$section};
-               my $optlist = join(" ", keys %$opts);
-               my @l = `bin/config $defargs $section $optlist`;
+               my $optlist = join(";", keys %$opts);
+               my %filtered_opts = map { my $t=$_; $t=~s/[#\$]+$//; $t => $$opts{$_} } keys %$opts;
+               my @l = `bin/config $defargs "$section\{$optlist\}"`;
                $? && exit 1;
                foreach my $o (@l) {
-                       $o =~ /^CF_([^=]+)="(.*)"\n$/ or die "Cannot parse bin/config output: $_";
-                       my $var = $$opts{$1};
+                       $o =~ /^CF_.*_([^=]+)='(.*)'\n$/ or die "Cannot parse bin/config output: $_";
+                       my $var = $filtered_opts{$1};
                        my $val = $2;
                        if (ref $var eq "SCALAR") {
                                $$var = $val;