SReview::Config(3pm) | User Contributed Perl Documentation | SReview::Config(3pm) |
SReview::Config - Self-reproducing and self-documenting configuration file system
use SReview::Config; my $config = SReview::Config->new('/etc/sreview/config.pm'); $config->define('name', 'The name of this element', 'default'); ... print "You configured " . $config->get('name') . " as the name\n"; print "Full configuration: \n" . $config->dump;
SReview::Config is a class to easily manage self-reproducing and self-documenting configuration. You create an SReview::Config object, populate it with possible configuration values, and then retrieve them.
Create a new SReview::Config object.
Define a new configuration value. Not legal after "get" has already been called.
Name should be the name of the configuration value. Apart from the fact that it should not have a sigil, it should be a valid name for a perl scalar variable.
Define a name as a deprecated way of configuring things. When this value is set, SReview::Config will issue a warning that this option is now deprecated, and that the user should use some other option instead.
The conversion subroutine is an optional argument that should mangle the value given to "oldname" into the value expected by "newname". If it returns nonzero, then SReview::Config will croak. It will receive a reference to the "config" object, the value that is trying to be set, and the name of the new parameter.
The default conversion sub just sets the value of the newname configuration without any conversion.
Defines a default value for a particular configuration parameter through a subroutine.
If the subroutine returns "undef", that value will be ignored (and the normal logic for defining a default will be used).
Should be used on a parameter that has already been defined
through
$config->define
Return the value of the given configuration item. Also finalizes the definitions of this configuration file; that is, once this method has been called, the "define" method above will croak.
The returned value will either be the default value configured at "define" time, the value configured in the configuration file, or the value set (in JSON format) in the environment variable "SREVIEW_name ", where name is the upper-case version of the name of the configuration item.
Change the current value of the given configuration item.
Note, this does not change the defaults, only the configured value.
Return the documentation string for the given name
Return a string describing the whole configuration.
Each configuration item will produced in one of the following two formats:
# Documentation value given to define #$name = "default value";
# Documentation value given to define $name = "current value";
Print a JSON value for the given configuration item. Prints the default item if this item hasn't been set a value.
Return a truthy value if the given configuration item is still at its default value.
It is currently not possible to load more than one configuration file in the same process space. This will be fixed at some point in the future.
2022-12-14 | perl v5.36.0 |