UR::ModuleConfig - manage dynamic configuration of modules.
package MyModule; use base qw(UR::ModuleConfig); MyModule->config(%conf); $val = MyModule->config('key'); %conf = MyModule->config;
This module manages the configuration for modules. Configurations can be read from files or set dynamically. Modules wishing to use the configuration methods should inherit from the module.
The methods deal with managing configuration.
MyModule->config(%config); $val = MyModule->config('key'); %conf = MyModule->config; my $obj = MyModule->new; $obj->config(%config);
This method can be called three ways, as either a class or object method. The first method takes a hash as its argument and sets the configuration parameters given in the hash. The second method takes a single argument which should be one of the keys of the hash that set the config parameters and returns the value of that config hash key. The final method takes no arguments and returns the entire configuration hash.
When called as an object method, the config for both the object and all classes in its inheritance hierarchy are referenced, with the object config taking precedence over class methods and class methods closer to the object (first in the @ISA array) taking precedence over those further away (later in the @ISA array). When called as a class method, the same procedure is used, except no object configuration is referenced.
Do not use configuration keys that begin with an underscore (
_). These are reserved for internal use.
This method checks to see if a value is set. Unlike config, it does not issue a warning if the key is not set. If the key is not set,
undef is returned. If the key has been set, the value of the key is returned (which may be
This method allows the developer to set configuration values, only if they are not already set.
$rv = $class->config_file(path => $path); $rv = $class->config_file(handle => $fh);
This method reads in the given file and expects key-value pairs, one per line. The key and value should be separated by an equal sign,
=, with optional surrounding space. It currently only handles single value values.
The method returns true upon success,
undef on failure.