NAME

Chronicle::Config::Reader - Simple configuration file reader.

SYNOPSIS

use strict;
use warnings;

use Chronicle::Config::Reader;

my %config;

my $helper = Chronicle::Config::Reader->new();

$helper->parseFile( \%config, "/etc/foo.rc" );

DESCRIPTION

This module is contains the code required to read a chronicle configuration file. The configuration files it reads are simple files consisting of lines which are of the form "key=value".

Additional features include:

Comment Handling

Comments are begun with the # character and continue to the end of the line.

Comments may occur at the start, middle, or end of a line.

Environmental variable expansion

Environmental variables are expanded if they are detected.

Command-execution and expansion

If backticks are found in configuration values they will be replaced with the output of the specified command.

The following snippet demonstrates these features:

# The path variable will be set to /bin:/sbin:...
path = $PATH

# Our hostname will be set
hostname = `hostname`

METHODS

Now follows documentation on the available methods.

new

This is the constructor, no arguments are required or expected.

parseFile

Parse a configuration file, and insert any values into the provided hash-reference.

The two parameters required are a hash-reference, which will be updated with the configuration-values, and the name of the configuration file to parse.

If the file specified does not exist no action is taken.

Sample usage:

$cfg->parse( \%config, "/etc/foo/config" );

parseLine

Parse a single line.

This method is called internally, but it is exposed in case it might be useful to other callers.

The two parameters required are a hash-reference, which will be updated with the configuration-values, and a line of configuration-file content which should be parsed.

If the line is missing, or consistes entirely of a comment, this is not a problem. (e.g. "# this is a comment" will result in no update to the hash-reference, but also raise no error.)

Sample usage:

$cfg->parseLine( \%config, 'user = $USER' );

LICENSE

This module is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or

b) the Perl "Artistic License".

AUTHOR

Steve Kemp <steve@steve.org.uk>