X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=site_perl%2FConf.pm;h=0b2d5b328122ef3a1e63282613058dcfb1d7cab1;hp=d3ef307c0d7c48eeb72b16561f6a8a24a92e1a14;hb=7613e14fd13aabb2a44bb26ca8640053f44930ea;hpb=f5edb1f305bdbdfa655feb43d2a70bb9b0063297 diff --git a/site_perl/Conf.pm b/site_perl/Conf.pm index d3ef307c0..0b2d5b328 100644 --- a/site_perl/Conf.pm +++ b/site_perl/Conf.pm @@ -3,8 +3,6 @@ package FS::Conf; use vars qw($default_dir); use IO::File; -$default_dir='/var/spool/freeside/conf'; - =head1 NAME FS::Conf - Read access to Freeside configuration values @@ -13,8 +11,10 @@ FS::Conf - Read access to Freeside configuration values use FS::Conf; + $conf = new FS::Conf "/config/directory"; + + $FS::Conf::default_dir = "/config/directory"; $conf = new FS::Conf; - $conf = new FS::Conf "/non/standard/config/directory"; $dir = $conf->dir; @@ -33,8 +33,8 @@ but this may change in the future. =item new [ DIRECTORY ] -Create a new configuration object. Optionally, a non-default directory may -be specified. +Create a new configuration object. A directory arguement is required if +$FS::Conf::default_dir has not been set. =cut @@ -53,7 +53,12 @@ Returns the directory. sub dir { my($self) = @_; - $self->{dir}; + my $dir = $self->{dir}; + -e $dir or die "FATAL: $dir doesn't exist!"; + -d $dir or die "FATAL: $dir isn't a directory!"; + -r $dir or die "FATAL: Can't read $dir!"; + -x $dir or die "FATAL: $dir not searchable (executable)!"; + $dir; } =item config @@ -68,11 +73,13 @@ sub config { my $fh = new IO::File "<$dir/$file" or return; if ( wantarray ) { map { - /^(.*)$/ or die "Illegal line in $dir/$file:\n$_\n"; + /^(.*)$/ + or die "Illegal line (array context) in $dir/$file:\n$_\n"; $1; } <$fh>; } else { - <$fh> =~ /^(.*)$/ or die "Illegal line in $dir/$file:\n$_\n"; + <$fh> =~ /^(.*)$/ + or die "Illegal line (scalar context) in $dir/$file:\n$_\n"; $1; } } @@ -94,8 +101,6 @@ sub exists { =head1 BUGS -The option to specify a non-default directory should probably be removed. - Write access (with locking) should be implemented. =head1 SEE ALSO @@ -108,6 +113,17 @@ Ivan Kohler 98-sep-6 sub exists forgot to fetch $dir ivan@sisd.com 98-sep-27 +$Log: Conf.pm,v $ +Revision 1.4 1999-05-11 10:09:13 ivan +try to diagnose strange multiple-line problem + +Revision 1.3 1999/03/29 01:29:33 ivan +die unless the configuration directory exists + +Revision 1.2 1998/11/13 04:08:44 ivan +no default default_dir (ironic) + + =cut 1;