@node IniConf, LWP, Image/Size, Module List
@unnumbered A Module for reading .ini-style configuration files


@unnumberedsec NAME

IniConf - A Module for reading .ini-style configuration files

@unnumberedsec DESCRIPTION

IniConf provides a way to have readable configuration files outside
your Perl script.  The configuration can be safely reloaded upon
receipt of a signal.

@unnumberedsec USAGE

Get a new IniConf object with the new method:

@example
$cfg = IniConf->new( -file => "/path/configfile.ini" );
$cfg = new IniConf -file => "/path/configfile.ini";
@end example

Optional named parameters may be specified after the configuration
file name.  See the new in the METHODS section, below.

INI files consist of a number of sections, each preceeded with the
section name in square brackets.  Parameters are specified in each
section as Name=Value.  Any spaces around the equals sign will be
ignored, and the value extends to the end of the line

@example
[section]
Parameter=Value
@end example

Both the hash mark (#) and the semicolon (;) are comment characters.
Lines that begin with either of these characters will be ignored.  Any
amount of whitespace may preceed the comment character.

Multiline or multivalued fields may also be defined ala UNIX "here
document" syntax:

@example
Parameter=<<EOT
value/line 1
value/line 2
EOT
@end example

You may use any string you want in place of "EOT".  Note that what
follows the "<<" and what appears at the end of the text MUST match
exactly, including any trailing whitespace.

See the METHODS section, below, for settable options.

Values from the config file are fetched with the val method:

@example
$value = $cfg->val(@'Section@', @'Parameter@');
@end example

If you want a multi-line/value field returned as an array, just
specify an array as the receiver:

@example
@@values = $cfg->val(@'Section@', @'Parameter@');
@end example

@unnumberedsec METHODS

@unnumberedsubsec new (-file=>$filename, [-option=>value ...] )

Returns a new configuration object (or "undef" if the configuration
file has an error).  One IniConf object is required per configuration
file.  The following named parameters are available:

@table @asis
@item @emph{-default} section
Specifies a section is used for default values.  For example, if you
look up the "permissions" parameter in the "users" section, but there
is none, IniConf will look to your default section for a "permissions"
value before returning undef.

@item @emph{-reloadsig} signame
You may specify a signal (such as SIGHUP) that will cause the
configuration file to be read.  This is useful for static daemons
where a full restart in order to realize a configuration change would
be undesirable.  Note that your application must be tolerant of the
signal you choose.  If a signal handler was already in place before
the IniConf object is created, it will be called after the
configuration file is reread.  The signal handler will not be
re-enabled until after the configuration file is reread any the
previous signal handler returns.

@item @emph{-reloadwarn} 0|1
Set -reloadwarn => 1 to enable a warning message (output to STDERR)
whenever the config file is reloaded.  The reload message is of the
form:

@example
PID <PID> reloading config file <file> at YYYY.MM.DD HH:MM:SS
@end example

See your system documentation for information on valid signals.

@item @emph{-nocase} 0|1
Set -nocase => 1 to handle the config file in a case-insensitive
manner (case in values is preserved, however).  By default, config
files are case-sensitive (i.e., a section named @'Test@' is not the same
as a section named @'test@').  Note that there is an added overhead for
turning off case sensitivity.

@end table
@unnumberedsubsec val ($section, $parameter)

Returns the value of the specified parameter in section $section.

@unnumberedsubsec setval ($section, $parameter, $value, [ $value2, ... ])

Sets the value of parameter $section in section $section to $value (or
to a set of values).  See below for methods to write the new
configuration back out to a file.

You may not set a parameter that didn@'t exist in the original
configuration file.  @strong{setval} will return undef if this is
attempted.  Otherwise, it returns 1.

@unnumberedsubsec ReadConfig

Forces the config file to be re-read.  Also see the @emph{-reloadsig}
option to the new method for a way to connect this method to a
signal (such as SIGHUP).

@unnumberedsubsec Sections

Returns an array containing section names in the configuration file.
If the @emph{nocase} option was turned on when the config object was
created, the section names will be returned in lowercase.

@unnumberedsubsec Parameters ($sectionname)

Returns an array containing the parameters contained in the specified
section.

@unnumberedsubsec GroupMembers ($group)

Returns an array containing the members of specified $group.  Groups
are specified in the config file as new sections of the form

@example
[GroupName MemberName]
@end example

This is useful for building up lists.  Note that parameters within a
"member" section are referenced normally (i.e., the section name is
still "Groupname Membername", including the space).

@unnumberedsubsec WriteConfig ($filename)

Writes out a new copy of the configuration file.  A temporary file
(ending in .new) is written out and then renamed to the specified
filename.  Also see BUGS below.

@unnumberedsubsec RewriteConfig

Same as WriteConfig, but specifies that the original configuration
file should be rewritten.

@unnumberedsec DIAGNOSTICS

@unnumberedsubsec @@IniConf::errors

Contains a list of errors encountered while parsing the configuration
file.  If the new method returns undef, check the value of this
to find out what@'s wrong.  This value is reset each time a config file
is read.

@unnumberedsec BUGS

@itemize @bullet
@item 
IniConf won@'t know if you change the signal handler that it@'s using
for config reloads.

@item 
The signal handling stuff is almost guaranteed not to work on non-UNIX
systems.

@item 
The output from [Re]WriteConfig/OutputConfig might not be as pretty as
it can be.  Comments are tied to whatever was immediately below them.

@item 
No locking is done by [Re]WriteConfig.  When writing servers, take
care that only the parent ever calls this, and consider making your
own backup.

@item 
The Windows INI specification (if there is one) probably isn@'t
followed exactly.  First and foremost, IniConf is for making
easy-to-maintain (and read) configuration files.

@end itemize
@unnumberedsec VERSION

Version 0.9 (beta)

@unnumberedsec AUTHOR

Scott Hutton (shutton@@indiana.edu)

@unnumberedsec COPYRIGHT

Copyright (c) 1996 Scott Hutton. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same
terms as Perl itself.

