.

Harvest::Config - configuration file parsing

DESCRIPTION

Parse Harvest-NG configuration files.

These files provide a means of defining nested key/value pairs, as follows.

A key/value pair can be defined in the following ways

Url: http://webharvest.sourceforge.net

<Url> http://webharvest.sourceforge.net </Url>

<Url urllist> <Url |urlprog>

In the last two examples, the contents of the ``Url'' key are read from the file ``urllist'', and from STDOUT of urlprog, respectively.

METHODS

$config=new Harvest::Config($format,$arg)

Create a new configuration object.

$format describes the type of configuration we're creating, it can be either 'file', in which case $arg is the name of a file to parse, 'string', in which case $arg is a string containing the configuration information, or it can be 'empty', in which case we're creating an empty configuration object.

In addition, $arg can be ``keepstring'' which will preserve the formating of the original string.

$config->add($key,$value);

Add $key to the configuration, with a value of $value. Collisions are handled by creating multiple entries for $key.

$key=$config->key($internalkey)

Return the real value of a key given its internal representation

@keys=$config->keys

Returns the list of _internal_ keys stored in the configuration object. To get an external key (such as the one used when the data was originally entered) use the $config->key method described above.

@vals=$config->allvalues($key)

If there were multiple values for $key in a file return all of these values

@vals=$config->arrayvalue($key)

Return the value of $key as a perl list, splitting on new lines or commas.

$config->check(@keys)

Check that the keys listed in the array are defined, and if not throw a die style exception.

$value=$config->value($key)

Return the data stored for the key $key.

$config->setdefault($key,@values)

Set a default value for a key. That is, the value will only be stored if data does not already exist for that key

$config->setvalue($key,@values)

Set the value of a key. This will overwrite any values already stored for the key, or create the key if no values are stored for it.

$config->write($file)

Write the current configuration information out to a file. Note that the acting of reading, then writing a configuration file is not idempotent, changes will result, especially when dealing with files that include other files.

$config->merge($cfg)

Merge the current Configuration object with the one contained in the Harvest::Config object $cfg.