OWL2Perl
view release on metacpan or search on metacpan
lib/OWL/Config.pm view on Meta::CPAN
foreach my $prefix (@INC) {
$realfilename = File::Spec->catfile ($prefix, $filename);
return $realfilename if -f $realfilename;
}
return undef;
}
# return value of a configuration argument; or add a new argument
sub param {
shift;
# If called with no arguments, return all the
# possible keys
return keys %Config unless @_;
# if called with a single argument, return the value
# matching this key
return $Config{$_[0]} if @_ == 1;
# more arguments means adding...
# return $Config{$_[0]} = $_[1];
my $ret = $Config{$_[0]} = $_[1];
OWL::Config->import_names ('OWLCFG');
return $ret;
}
# remove one, more, or all configuration arguments
sub delete {
shift;
# if called with no arguments, delete all keys
%Config = () and return unless @_;
# if called with arguments, delete the matching keys
foreach my $key (@_) {
delete $Config{$key};
}
}
# return a stringified version of all configuration options; an
# optional argument is a name for variable into which it is
# stringified (I do not know how to express it better: simply speaking
# this argument is passed to the Data::Dumper->Dump as the variable
# name)
sub dump {
shift;
my $varname = @_ ? shift : 'CONFIG';
require Data::Dumper;
return Data::Dumper->Dump ( [\%Config], [$varname]);
}
# imports names into the caller's namespace as global variables;
# adapted from the same method in Config::Simple
sub import_names {
shift;
my $namespace = @_ ? shift : (caller)[0];
return if $namespace eq 'OWL::Config';
no strict 'refs';
no warnings; # avoid "Useless use of a variable..."
while ( my ($key, $value) = each %Config ) {
$key =~ s/\W/_/g;
${$namespace . '::' . uc($key)} = $value;
}
}
# return a list of configuration files successfully read (so far)
sub ok_files {
return sort keys %Success;
}
# return a hash of configuration files un-successfully read (so far) -
# with corresponding error messages
sub failed_files {
return %Unsuccess;
}
1;
__END__
( run in 1.651 second using v1.01-cache-2.11-cpan-13bb782fe5a )