NAME
StanzaFile - read, parse, and write files containing "stanzas".
SYNOPSIS
# Parse a .ini format file into stanzas.
#
use StanzaFile ;
my $a = new StanzaFile(file_name=>"/etc/wvdial.conf") ;
# Add a new stanza to a StanzaFile.
#
$a->add(new Stanza('Stanza Name')) ;
# Check for a stanza's existance.
#
if ($a->exists('New Stanza'))
{
...
} ;
# Parse a .ini format file into stanzas.
#
use StanzaFile ;
my $a = new StanzaFile ;
$a->read(file_name=>"/etc/wvdial.conf") ;
# Produce a string version of the StanzaFile
# (Comments and other formatting are lost)
#
my $theString = $a->asString() ;
# Write the StanzaFile.
#
$a->write("/etc/newFile.conf") ;
# Add a new stanza to the file, replacing the stanza if it
# already exists in the file.
#
$theNewStanza = new Stanza('New Stanza') ;
$a->replace($theNewStanza) ;
# Access the "header" stanza.
#
my $theHeaderStanza = $a->header() ;
# Order in which the stanzas were added to the stanza file.
#
my @theAdditionOrder = $a->order() ;
# Get a stanza object from the stanza file.
#
my $theStanzaObject = $a->stanza('The Stanza') ;
DESCRIPTION
A number of Linux configuration files are stored in a Windows format know as "stanzas" or WINDOWS.INI format. These files are of the form
[name]
variable=value
variable1=value1
...
[name1]
variableA=valueA
variable1A=value1A
and so on. This class is designed to provide parsing and processing capabilities for the WINDOWS.INI format and provide a general enough framework so that other formats of stanzas can be easily supported (see StanzaFile::Grub for an example).
With the StanzaFile and it's companion class Stanza it is reasonably easy to read, parse, process, and write virtually any type of stanza formatted information.
EXAMPLES
The following is a somewhat contrived example, but it shows the merging of two StanzaFiles.
my $a = new StanzaFile("/etc/wvfile.conf") ;
my $b = new StanzaFile("newWvfile.conf") ;
foreach ($b->order())
{
if ($a->exists($_))
{
$a->stanza($_)->merge($b->stanza($_)) ;
}
else
{
$a->add($b->stanza($_)) ;
} ;
} ;
$a->write(file_name=>"/etc/mergedWvdial.conf") ;
BUGS
None known.
WARNINGS
AUTHOR
Dick Munroe (munroe@csworks.com).
I'm looking for work (contract or permanent). I do a lot more than just hack Perl. Take a look at my:
Resume: http://www.csworks.com/resume Skills: http://www.csworks.com/skills CV: http://www.csworks.com/cv
for the gory details. If you see a match, drop me a note and we'll see what we can work out.