This is RCS version: $Revision: 3.1 $.
DEFAULT blocks which specify default behaviors (i.e. default
properties) which may be included by NAME blocks which specify the
default behaviors for specific entities (machines, for example).
Comments are as in shell and Perl: anything after a #.
The DEFAULT block looks like this:
The default_tag may be any atomic string and is used by NAME
blocks to include properties.
A NAME block looks like this:
NOTE: it is important to know that when asking for the value of a property for an entry, the explicit properties are checked first, then the default blocks are checked in the order they are specified in the block This is to allow you to override defaults on a particular entry without having to reenter other useful defaults
Information is extracted from the file via the get method. From
the above example you could call
and you would get 'value0' back as your answer.
If the flexibility (and associated syntax) of the NAME blocks is
too much for your application, you may instead use the GLOBAL
directive. For example:
The GLOBAL directive must be at the end of the configuration file.
The get syntax for GLOBALs is simpler:
The values of properties may be extended over multiple lines if in the
value position you place the token '@{'. All following lines,
until a matching '@}' is found are assigned to the propery. For
example:
Text included between '@{' and '@}' does NOT get tokenized, comments are ignored (that is, included in the property), but macro substitution does take place.
NOTE: all the @@-directives must be syntactically complete on a single line. That is, you cannot spread a complex conditional or assignment statement over several lines.
A value is assigned to a macro in the following way:
The @@define directive has global scope, it can occur at the top
level or in a DEFAULT or NAME block, but is in effect for all
sections of the configuration file following it.
Macros may be accessed by prefixing the symbol name with @$, and
may occur anywhere in the file. So @$symbol will have the string
``This is a value.'' substituted for it.
There is a primitive conditional facility which is intended to interact with the macros:
Where...
Notice that you can do things like the following:
or this:
This last form assigns the value -ef to the NAME bob block
property ps_flags if the program is run on a Solaris machine. It
is an error to use this form outside a block.
Notice the syntax for @@ifdefined:
You do not prefix the macro name with @$ when testing if it is
defined or not.
EXPERIMENTAL: Certain macros are defined when the ConfigFile object is created. As of this version, only SunOS and Solaris will assign all of these properly.
Of course, these may be overwritten in your own configuration files.
This opens and parses the configuration file specified.
This reads the specified config file. All the interesting work happens here. One useful trick you can use this for is to read in several configuration files, one of which may simply assign macro values.
Returns undef for certain errors.
If you call
ConfigFile::get
for an entity which does not have an
entry the default return value is undef. This call sets up a
default set of properties for entities without explicit NAME
blocks.
The first form of
ConfigFile::get
looks for the value and returns
undef if there is no such entry or property. The second form looks
for the property of a entity, but if no such entity is specified in a
NAME block, returns the value for the default block, but will
return undef if there is no such DEFAULT default_tag block or
property. See above for in
ConfigFile::set_default
for a nicer way
to deal with defaults.
The last form is for GLOBAL properties.
This returns a list of all non-default properties for the specified block. The second form, without arguments, returns a list of all GLOBAL properties.
Note that this returns a list of the property names, not the actual values.
This assigns the value of a property for a specific entry.
This acts exactly like a DEFAULT some_tag clause in a NAME
block. This is the way to add finer grained default behavior than is
offered by
ConfigFile::set_default
.
Returns a list of DEFAULTs available to this NAME block. Returns
undef if there is no such NAME or if it has no DEFAULTs.
This corresponds to the @@define directive in the configuration
language. Obviously, this is only useful before a call to
ConfigFile::read
. For the above example, you will need to
reference ``@$macro'' to get interpolation.
http://www.biostat.wisc.edu/~annis
This module has subsequently been used in a number of applications. It is used in all parts of my machine monotoring system, Mom. It has also been put to quite peculiar use as a definition language for GUIs using PerlTk.
ConfigFile 1.1 General Idea.
ConfigFile 1.3 Stable, working version. Used in several applications at the BCG.
ConfigFile 2.1 IA version with @@define, @@if* forms and GLOBAL block.
ConfigFile 2.5 Stable version with many bugfixes. Used in several applications.
ConfigFile 2.6 External release: ConfigFile-1.0.
ConfigFile 3.0 New, sensible methods: read, get_all, defaults. Removed some of the die calls.
ConfigFile 3.1 Can define macros from the Perl interface. External release: ConfigFile-1.1.
This documentation could be clearer.