Reads a configuration file of directives and values.
# comments start with a #, and blank lines are ignored
Input /etc/data_source # the value follows the directive name
HomePage http://www.w3.org/
# values can be quoted
Comment "here is a value with trailing spaces "
my $c = new ConfigReader::DirectiveStyle;
directive $c 'Input', undef, '~/input'; # specify default value,
# but no parsing needed
required $c 'HomePage', 'new URI::URL'; # create URI::URL object
ignore $c 'Comment'; # Ignore this directive.
$c->load('my.config');
open(IN, $c->value("Input"));
$c->define_accessors(); # creates Input() and HomePage()
retrieve(HomePage());
DirectiveStyle is a subclass of ConfigReader. The methods to define the directives in the configuration file are documented there.
Comments are introduced by the ``#'' character, and continue until the end of line. Like in Perl, the backslash character ``\'' may be used in the directive values for the various standard sequences:
\t tab
\n newline
\r return
\f form feed
\v vertical tab, whatever that is
\b backspace
\a alarm (bell)
\e escape
\033 octal char
\x1b hex char
The value may also be quoted, which lets you include leading or trailing spaces. The quotes are stripped off before the value is returned.
DirectiveStyle itself only reads the configuration file. Most of the hard work of defining the directives and parsing the values is done in its superclass, ConfigReader::Values. You should be able to easily modify or subclass DirectiveStyle to read a different style of configuration file.
new( [$spec] )
$spec argument, see
DirectiveStyle::new().
load($file, [$untaint])
load(), you'll want to define the directives
using the methods described in ConfigReader::Values.
Reads a configuration from $file. The default values for any directives not present in the file are assigned.
Normally configuration values are tainted like any data read from a file.
If the configuration file comes from a trusted source, you can untaint all
the values by setting the optional $untaint argument to a true
value (such as 'UNTAINT').
parse_line($line, $whence, $untaint)
$whence is a string describing the source of the
line. Returns a two-element array of the directive and the value string, or
the empty array () if the line is blank or only contains a comment.
parse_value_string($str, $whence)