Changed config handling. More fixes needed..
[licom.git] / lib / LiCoM / Config.pm
index c631a4b..f62c7d4 100644 (file)
@@ -5,13 +5,60 @@ use warnings;
 
 use Exporter;
 
-@LiCoM::Config::EXPORT_OK = ('get_config');
+@LiCoM::Config::EXPORT_OK = ('get_config read_config');
 @LiCoM::Config::ISA = ('Exporter');
 
+our $Config = {};
+
 return (1);
 
+=head1 STATIC FUNCTIONS
+
+=over 4
+
+=item LiCoM::Config-E<gt>B<get_config> (I<$key>)
+
+Returns the value for I<$key> or undef if it's unknown.
+
+=cut
+
 sub get_config
 {
+       my $pkg = shift;
+       my $key = shift;
+
+       if (!%$Config)
+       {
+               read_config ();
+       }
+
+       return ($Config->{$key});
+}
+
+=item LiCoM::Config-E<gt>B<set_config> (I<$key>, I<$value>)
+
+Sets the value of I<$key> to I<$value>.
+
+=cut
+
+sub set_config
+{
+       my $pkg = shift;
+       my $key = shift;
+       my $val = shift;
+
+       $Config->{$key} = $val;
+}
+
+=item LiCoM::Config-E<gt>B<read_config> ([I<@files>])
+
+Read the config from the files given or F</etc/licom/licom.conf> and
+F<~/.licomrc> if no files were given.
+
+=cut
+
+sub read_config
+{
        my @files = ('/etc/licom/licom.conf');
 
        if (@_)
@@ -59,3 +106,11 @@ sub read_file
 
        return ($config);
 }
+
+=back
+
+=head1 AUTHOR
+
+Florian octo Forster E<lt>octo at verplant.orgE<gt>
+
+=cut