NAME
BW::Config.pm
SYNOPSIS
use BW::Config;
my $config = BW::Config->new( { filename => $filename } );
my $values = $config->values;
my $config = BW::Config->new;
$config->parse( { filename => $filename } );
my $values = $config->values;
my $errstr;
if(($errstr = $config->error)) {
# report $errstr here
}
DESCRIPTION
BW::Config reads and parses simple configuration files.
METHODS
- version
-
Return the version string.
- filename
-
Set or return the filename used by BW::Config->parse.
- keywords
-
Return an arrayref of keywords, in the order they appear in the config file.
- values
-
Return a hashref of key/value pairs.
- arrays
-
Return a hashref of key/arrayref pairs for multi-item values.
- error
-
Return the latest error condition. The error string is cleared when it is read.
FILE FORMAT
The config file format is very simple. It's a line-oriented format where keys and values are separated by an equals sign (=).
key = value
Whitespace surrounding the keys and values is ignored.
Array values (multiple values per key) are separated by colons.
key = value:value:value:value
If you want the raw colon-separated value, you can get that with the values method.
Lines that begin with '#' are ignored.
# this is a comment
anything after '#' to the end of the line is considered a comment and is ignored.
key = value # comment comment blah blah blah
All leading and trailing whitespace are trimed, and a key without a value is assumed to have a zero-length string as the value.
NOTES
Values are never undef. A zero-length string is provided for null content.
Errors are reported via the BW::Config->error method. It's a good idea to check this before using the values from your config file.
if((my $errorstring = $config->error)) { die $errorstring; # or some other way of reporting the error }
BUGS AND MISFEATURES
There is no quoting mechanism for the config file. The colon-separated arrays are particularly weak. There should be a way to quote a colon so it's not interpreted as such.
There should also be a way to quote strings and quote marks. These may be features for a future version.
AUTHOR
Written by Bill Weinman <http://bw.org/>.
COPYRIGHT
Copyright (c) 1995-2010 The BearHeart Group, LLC
HISTORY
2010-02-14 bw 1.1 - initial CPAN version 2008-04-02 bw - initial BW-Lib version