summaryrefslogtreecommitdiff
path: root/Echolot/Config.pm
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2002-07-06 21:35:04 +0000
committerPeter Palfrader <peter@palfrader.org>2002-07-06 21:35:04 +0000
commit2d522aed78edeaa25f8640698812d651ca0dd411 (patch)
treed6b0c4be1d7939254e007311acbeaf6f526fb449 /Echolot/Config.pm
parentd1f11a5be97a25e38bd18e55cf5bc2b1dfeb401e (diff)
Find config file automagically
Diffstat (limited to 'Echolot/Config.pm')
-rw-r--r--Echolot/Config.pm46
1 files changed, 44 insertions, 2 deletions
diff --git a/Echolot/Config.pm b/Echolot/Config.pm
index f764ffe..8c62451 100644
--- a/Echolot/Config.pm
+++ b/Echolot/Config.pm
@@ -1,7 +1,7 @@
package Echolot::Config;
# (c) 2002 Peter Palfrader <peter@palfrader.org>
-# $Id: Config.pm,v 1.14 2002/07/06 20:15:12 weasel Exp $
+# $Id: Config.pm,v 1.15 2002/07/06 21:35:04 weasel Exp $
#
=pod
@@ -12,6 +12,29 @@ Echolot::Config - echolot configuration
=head1 DESCRIPTION
+Sets default configuration options and
+reads configuration from the config file.
+
+=head1 FILES
+
+The configuration file is searched in those places in that order:
+
+=over
+
+=item the file pointed to by the B<ECHOLOT_CONF> environment variable
+
+=item `pwd`/pingd.conf
+
+=item $HOME/echolot/pingd.conf
+
+=item $HOME/pingd.conf
+
+=item $HOME/.pingd.conf
+
+=item /etc/pingd.conf
+
+=back
+
=cut
use strict;
@@ -22,6 +45,14 @@ use Carp;
my $CONFIG;
+my @CONFIG_FILES =
+ ( $ENV{'ECHOLOT_CONF'},
+ 'pingd.conf',
+ $ENV{'HOME'}.'/echolot/pingd.conf',
+ $ENV{'HOME'}.'/pingd.conf',
+ $ENV{'HOME'}.'/.pingd.conf',
+ '/etc/pingd.conf' );
+
sub init($) {
my ($params) = @_;
@@ -92,9 +123,20 @@ sub init($) {
verbose => 0
};
+
+ my $configfile = undef;
+ for my $filename ( @CONFIG_FILES ) {
+ if ( defined $filename && -e $filename ) {
+ $configfile = $filename;
+ last;
+ };
+ };
+
+ die ("no Configuration file found\n") unless defined $configfile;
+
{
my $parser = new XML::Parser(Style => 'Tree');
- my $tree = $parser->parsefile('pingd.conf');
+ my $tree = $parser->parsefile($configfile);
my $dump = new XML::Dumper;
$CONFIG = $dump->xml2pl($tree);
}