Wouter Verhelst

NAME

SReview::Config - Self-reproducing and self-documentating configuration file system

SYNOPSIS

  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;

DESCRIPTION

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.

METHODS

SReview::Config->new('path/to/filename');

Create a new SReview::Config object.

$config->define(name, doc, default)

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.

$config->get('name')

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, or the value configured in the configuration file.

$config->set('name', value);

Change the current value of the given configuration item.

Note, this does not change the defaults, only the configured value.

$config->describe('name');

Return the documentation string for the given name

$config->dump

Return a string describing the whole configuration.

Each configuration item will produced in one of the following two formats:

  • For an item that only has a default set:

      # Documentation value given to define
      #$name = "default value";
  • For an item that has a different value configured (either through the configuration file, or through set):

      # Documentation value given to define
      $name = "current value";

BUGS

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.