Libconf::Glueconf - Libconf high level common module
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.
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();
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)
Here is the list of available templates, see their documentation for specific methods
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
the Libconf::Glueconf::Generic::KeyValue manpage : [ key - value ] atoms.
the Libconf::Glueconf::Generic::KeyValues manpage : [ key - value1,value2 ] atoms.
the Libconf::Glueconf::Generic::ValueSection manpage : [ Section ] with [ Value ] atoms.
the Libconf::Glueconf::Generic::Shell manpage : shell style configuration files.
These templates are made to parse precise configuration files.
the Libconf::Glueconf::NUT::Ups_conf manpage : template for UPS hardwares configuration files
the Libconf::Glueconf::Networking::Hosts manpage : template for /etc/hosts file
the Libconf::Glueconf::Networking::Resolv manpage : template for /etc/resolv.conf file
the Libconf::Glueconf::Networking::Sshd_config manpage : template for ssh deamon config file
the Libconf::Glueconf::Postfix::Main_cf manpage : template for postfix main.cf like files
the Libconf::Glueconf::Samba::Smb_conf manpage : template for /etc/samba/smb.conf like files
the Libconf::Glueconf::X::XF86Config manpage : template for xorg.conf like files
the Libconf::Glueconf::X::Xdm manpage : template for xdm configuration file
the Libconf::Glueconf::X::Gdm manpage : template for gdm and kdm configuration files
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().
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().
$template->set_option(filename => '/etc/test.cfg');
description
sets an option after instanciation of the object.
my $value = $template->get_option('filename');
description
get the value of an option after instanciation of the object.
$template->toXMLString();
description
toXMLString exports the template informations into an XML string.
The optional $format parameter sets the indenting of the output.
$template->toXMLFile('xml_filename');
description
toXMLFile exports the template informations into an XML file.
The optional $format parameter sets the indenting of the output.
$template->fromXMLString($xml_string);
description
fromXMLString imports the data from an XML string in the format previously generated by toXMLString
$template->fromXMLFile('file.xml');
description
fromXMLFile imports the data from an XML file previously generated by toXMLFile
description
get the comments of an atom, described by the structure.
example
$comments = $samba->get_comments('{global}{workgroup}')
description
set the comments of an atom, described by the structure.
example
$samba->set_comments('{global}{workgroup}', $comments)
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;
description
returns the comment status of the atom.
example
if ($samba->commented('{global}{workgroup}')) { ... }