X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=lib%2FLiCoM%2FConfig.pm;h=295f7eb0afa9d9ceedcd4234d7726f407e44d93b;hb=328bdcb841ecaa72c69379e6ccd7165f44e7c2e4;hp=f62c7d4e052b2ceb52f56cd5a8127677e1ba0cfc;hpb=58514068dafe37b69bca7d34e5d4bc2e6e234c9a;p=licom.git diff --git a/lib/LiCoM/Config.pm b/lib/LiCoM/Config.pm index f62c7d4..295f7eb 100644 --- a/lib/LiCoM/Config.pm +++ b/lib/LiCoM/Config.pm @@ -2,21 +2,22 @@ package LiCoM::Config; use strict; use warnings; +use Carp (qw(cluck confess)); use Exporter; -@LiCoM::Config::EXPORT_OK = ('get_config read_config'); +@LiCoM::Config::EXPORT_OK = (qw(get_config set_config read_config)); @LiCoM::Config::ISA = ('Exporter'); our $Config = {}; return (1); -=head1 STATIC FUNCTIONS +=head1 EXPORTED FUNCTIONS =over 4 -=item LiCoM::Config-EB (I<$key>) +=item B (I<$key>) Returns the value for I<$key> or undef if it's unknown. @@ -24,9 +25,10 @@ Returns the value for I<$key> or undef if it's unknown. sub get_config { - my $pkg = shift; my $key = shift; + cluck ("\$key was not defined") unless (defined ($key)); + if (!%$Config) { read_config (); @@ -35,7 +37,7 @@ sub get_config return ($Config->{$key}); } -=item LiCoM::Config-EB (I<$key>, I<$value>) +=item B (I<$key>, I<$value>) Sets the value of I<$key> to I<$value>. @@ -43,14 +45,15 @@ Sets the value of I<$key> to I<$value>. sub set_config { - my $pkg = shift; my $key = shift; my $val = shift; + cluck ("\$key was not defined") unless (defined ($key)); + $Config->{$key} = $val; } -=item LiCoM::Config-EB ([I<@files>]) +=item B ([I<@files>]) Read the config from the files given or F and F<~/.licomrc> if no files were given. @@ -75,10 +78,10 @@ sub read_config my $file = $_; next unless (-r $file); - read_file ($file, $config); + read_file ($file, $Config); } - return ($config); + return ($Config); } sub read_file