5 use Carp (qw(cluck confess));
7 use File::Basename (qw(dirname));
11 @LiCoM::Config::EXPORT_OK = (qw(get_config set_config read_config));
12 @LiCoM::Config::ISA = ('Exporter');
18 =head1 EXPORTED FUNCTIONS
22 =item B<get_config> (I<$key>)
24 Returns the value for I<$key> or undef if it's unknown.
32 cluck ("\$key was not defined") unless (defined ($key));
39 return ($Config->{$key});
42 =item B<set_config> (I<$key>, I<$value>)
44 Sets the value of I<$key> to I<$value>.
53 cluck ("\$key was not defined") unless (defined ($key));
55 $Config->{$key} = $val;
58 =item B<read_config> ([I<@files>])
60 Read the config from the files given or F</etc/licom/licom.conf> and
61 F<~/.licomrc> if no files were given.
67 my @files = ('/etc/licom/licom.conf');
73 elsif (defined ($ENV{'HOME'}) and (-d $ENV{'HOME'}))
75 push (@files, $ENV{'HOME'} . '/.licomrc');
77 elsif (defined ($ENV{'SCRIPT_FILENAME'}))
79 push (@files, dirname ($ENV{'SCRIPT_FILENAME'}) . '/licom.conf');
85 next unless (-r $file);
87 read_file ($file, $Config);
95 my $file = @_ ? shift : '/etc/licom/licom.conf';
96 my $config = @_ ? shift : {};
99 open ($fh, "< $file") or die ("open ($file): $!");
105 if ($line =~ m/^(\w+):\s*"(.+)"\s*$/)
110 $config->{$key} = $val;
123 Florian octo Forster E<lt>octo at verplant.orgE<gt>