1 # Perl module for parsing Sherlock configuration files (using the config utility)
3 # (c) 2002 Martin Mares <mj@ucw.cz>
5 # This software may be freely distributed and used according to the terms
6 # of the GNU Lesser General Public License.
8 package Sherlock::Config;
16 our $DefaultConfigFile = "";
21 my $override_config = 0;
22 push @options, "config|C=s" => sub { my ($o,$a)=@_; $defargs .= " -C'$a'"; $override_config=1; };
23 push @options, "set|S=s" => sub { my ($o,$a)=@_; $defargs .= " -S'$a'"; };
24 Getopt::Long::GetOptions(@options) or return 0;
25 if (!$override_config && $DefaultConfigFile) {
26 $defargs = "-C'$DefaultConfigFile' $defargs";
28 foreach my $section (keys %Sections) {
29 my $opts = $Sections{$section};
30 my $optlist = join(" ", keys %$opts);
31 my @l = `bin/config $defargs $section $optlist`;
34 $o =~ /^CF_([^=]+)='(.*)'\n$/ or die "Cannot parse bin/config output: $_";
37 if (ref $var eq "SCALAR") {
39 } elsif (ref $var eq "ARRAY") {
42 die ("Sherlock::Config::Parse: don't know how to set $o");