Chronicle::Config::Reader - Simple configuration file reader.
use strict; use warnings; use Chronicle::Config::Reader; my %config; my $helper = Chronicle::Config::Reader->new(); $helper->parseFile( \%config, "/etc/foo.rc" );
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:
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 variables are expanded if they are detected.
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`
Now follows documentation on the available methods.
This is the constructor, no arguments are required or expected.
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" );
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.)
"# this is a comment"
$cfg->parseLine( \%config, 'user = $USER' );
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".
Steve Kemp <steve@steve.org.uk>
To install App::Chronicle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Chronicle
CPAN shell
perl -MCPAN -e shell install App::Chronicle
For more information on module installation, please visit the detailed CPAN module installation guide.