NAME

Libconf::Glueconf - Libconf high level common module

DESCRIPTION

Libconf::Glueconf is a class that represents a config file at a high level. It provides an easy-to-use and powerful structure to edit the config file.

SYNOPSYS

PERL

This is the high level layer of libconf. You should use it to read/modify/write the informations to the config files. Here are some examples, but you should look in the specific modules below for more examples.

use Libconf::Glueconf::Samba::Smb_conf;
$samba = new Libconf::Glueconf::Samba::Smb_conf({ filename => '/etc/samba/smb.conf' });
$samba->{homes}->{writable} = 'TEST';
$samba->{global}->{workgroup} eq 'WORKGROUP' or die "workgroup is not correct\n";
$samba->write_conf(); # write back to /etc/samba/smb.conf
$samba->write_conf('/tmp/smb.conf'); # write to an alternate file 


use Libconf::Glueconf::X::XF86Config;
use Data::Dumper;
$Data::Dumper::Deepcopy = 1;
$Data::Dumper::Quotekeys = 0;
$xorg = new Libconf::Glueconf::X::XF86Config({ filename => '/etc/X11/xorg.conf'} );
print Dumper($xorg);

use Libconf::Glueconf::System::Inittab;
$inittab = new Libconf::Glueconf::System::Inittab({ filename => '/etc/inittab' });
$inittab->{id}->{runlevels} = '3';
$inittab->write_conf();

C, PYTHON, RUBY

Use the following module list, take the last 2 words, and replace :: with / Example : Libconf::Glueconf::Generic::KeyValue will become 'Generic/KeyValue'. Use it as arguments to Conf2Xml.conf2xml (ruby), conf2xml (python), conf2xml (c). More details available here (XXX TODO need to be written)

MODULE LIST

Here is the list of available templates, see their documentation for specific methods

Generic templates

You should use these if there is no specific templates fitting your needs. Look at their documentation to get the options you caan use to change their behaviour

Generic - KeyValue

Libconf::Glueconf::Generic::KeyValue : [ key - value ] atoms.

Generic - KeyValues

Libconf::Glueconf::Generic::KeyValues : [ key - value1,value2 ] atoms.

Generic - ValuesSection

Libconf::Glueconf::Generic::ValueSection : [ Section ] with [ Value ] atoms.

Generic - Shell

Libconf::Glueconf::Generic::Shell : shell style configuration files.

Specific templates

These templates are made to parse precise configuration files.

NUT - Ups_conf

Libconf::Glueconf::NUT::Ups_conf : template for UPS hardwares configuration files

Networking - Hosts

Libconf::Glueconf::Networking::Hosts : template for /etc/hosts file

Networking - Resolv

Libconf::Glueconf::Networking::Resolv : template for /etc/resolv.conf file

Networking - Sshd_config

Libconf::Glueconf::Networking::Sshd_config : template for ssh deamon config file

Postfix - Main_cf

Libconf::Glueconf::Postfix::Main_cf : template for postfix main.cf like files

Samba - Smb_conf

Libconf::Glueconf::Samba::Smb_conf : template for /etc/samba/smb.conf like files

X - XF86Config

Libconf::Glueconf::X::XF86Config : template for xorg.conf like files

X - Xdm

Libconf::Glueconf::X::Xdm : template for xdm configuration file

X - Gdm

Libconf::Glueconf::X::Gdm : template for gdm and kdm configuration files

GLUECONF GENERAL METHODS (PERL ONLY)

read_conf()
use Data::Dumper;
my $structure = new Libconf::Glueconf::Some::Module;
$structure->read_conf();
print Dumper($structure) . "\n";

description

This method reads the config file, and maps it to the structure. It doesn't use any argument for its own use, but you can give it arguments, they will be passed to the underlying Libconf::Templates::read_conf().

write_conf()
my $structure = new Libconf::Glueconf::Some::Module;
$structure->read_conf();
... edit $structure ...
$structure->write_conf();

description

This method writes the structure back to the config file. It doesn't use any argument for its own use, but you can give it arguments, they will be passed to the underlying Libconf::Templates::write_conf().

set_option($key, $value)
$template->set_option(filename => '/etc/test.cfg');

description

sets an option after instanciation of the object.

get_option($key)
my $value = $template->get_option('filename');

description

get the value of an option after instanciation of the object.

toXMLString($format)
$template->toXMLString();

description

toXMLString exports the template informations into an XML string.

The optional $format parameter sets the indenting of the output.

toXMLFile($filename, $format)
$template->toXMLFile('xml_filename');

description

toXMLFile exports the template informations into an XML file.

The optional $format parameter sets the indenting of the output.

fromXMLString($xml_string)
$template->fromXMLString($xml_string);

description

fromXMLString imports the data from an XML string in the format previously generated by toXMLString

fromXMLFile($filename)
$template->fromXMLFile('file.xml');

description

fromXMLFile imports the data from an XML file previously generated by toXMLFile

get_comments('path description')

description

get the comments of an atom, described by the structure.

example

$comments = $samba->get_comments('{global}{workgroup}')

set_comments('path description', $comments)

description

set the comments of an atom, described by the structure.

example

$samba->set_comments('{global}{workgroup}', $comments)

set_commented('path description', $value)

description

change the status of the atom to be commented or uncommented. A commented line will output commented with the first comment of $self->{comment_struct}

example

$samba->set_commented('{global}{workgroup}', 1)

when outputed, the line will be something like : # workgroup=foo;

commented('path description')

description

returns the comment status of the atom.

example

if ($samba->commented('{global}{workgroup}')) { ... }