perfSONAR_PS-Services-MA-perfSONARBUOY
view release on metacpan or search on metacpan
lib/perfSONAR_PS/OWP/Conf.pm view on Meta::CPAN
#$Conf::VERSION='1.0';
# Eventually set using $sysconfig autoconf variable.
$Conf::CONFPATH = '~'; # default dir for config files.
$Conf::GLOBALCONFENV = 'OWPGLOBALCONF';
$Conf::DEVCONFENV = 'OWPCONF';
$Conf::GLOBALCONFNAME = 'owmesh.conf';
#
# This hash is used to privide default values for "some" parameters.
#
my %DEFS = (
OWAMPDPIDFILE => 'owampd.pid',
OWAMPDINFOFILE => 'owampd.info',
OWPBINDIR => "$FindBin::Bin",
CONFDIR => "$Conf::CONFPATH/",
);
# Opts that are arrays.
# (These options are automatically split with whitespace - and the return
# is set as an array reference. These options can also show up on more
# than one line, and the values will append onto the array.)
# (Syntax is [val val val] )
my %ARRS;
# Keep hash of all 'types' of sub-hashes in the config hash.
my %HASHOPTS;
=head2 new()
TDB
=cut
sub new {
my ( $class, @initialize ) = @_;
my $self = {};
bless $self, $class;
$self->init(@initialize);
return $self;
}
=head2 resolve_path()
TDB
=cut
sub resolve_path {
my ( $self, $path ) = @_;
my ( $home, $user, $key );
if ( ( $path =~ m#^~/#o ) || ( $path =~ m#^~$#o ) ) {
$home
= $ENV{"HOME"}
|| $ENV{"LOGDIR"}
|| ( getpwuid($<) )[7]
|| "BOGUSHOMEDIR";
$path =~ s#^\~#$home#o;
}
elsif ( ($user) = ( $path =~ m#^~([^/]+)/.*#o ) ) {
$home = ( getpwnam($user) )[7] || "BOGUSHOMEDIR";
$path = $home . substr( $path, length($user) + 1 );
}
while ( ($key) = ( $path =~ m#\$([^\/]+)#o ) ) {
$path =~ s/\$$key/$ENV{$key}/g;
}
while ( ($key) = ( $path =~ m#\$\{([^\}]+)\}#o ) ) {
$path =~ s/\$\{$key\}/$ENV{$key}/g;
}
return $path;
}
=head2 load_line()
grok a single line from the config file, and adding that parameter
into the hash ref passed in, unless skip is set.
=cut
sub load_line {
my ( $self, $line, $href, $skip ) = @_;
my ( $pname, $val );
$_ = $line;
return 1 if (/^\s*#/); # comments
return 1 if (/^\s*$/); # blank lines
# reset any var
if ( ($pname) = /^\!(\w+)\s+/o ) {
$pname =~ tr/a-z/A-Z/;
delete ${$href}{$pname} if ( !defined($skip) );
return 1;
}
# bool
if ( ($pname) = /^(\w+)\s*$/o ) {
$pname =~ tr/a-z/A-Z/;
${$href}{$pname} = 1 if ( !defined($skip) );
return 1;
}
# array assignment
if ( ( ( $pname, $val ) = /^(\w+)\s+\[(.*?)\]\s*$/o ) ) {
$_ = $val;
$pname =~ tr/a-z/A-Z/;
$ARRS{$pname} = 1;
return 1 if ( defined($skip) );
push @{ ${$href}{$pname} }, split;
return 1;
}
# assignment
if ( ( ( $pname, $_ ) = /^(\w+)\s+(.*?)\s*$/o ) ) {
( run in 0.949 second using v1.01-cache-2.11-cpan-364913b4093 )