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

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

Generic - KeyValues

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

Generic - ValuesSection

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

Generic - Shell

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

Specific templates

These templates are made to parse precise configuration files.

NUT - Ups_conf

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

Networking - Hosts

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

Networking - Resolv

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

Networking - Sshd_config

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

Postfix - Main_cf

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

Samba - Smb_conf

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

X - XF86Config

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

X - Xdm

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

X - Gdm

the Libconf::Glueconf::X::Gdm manpage : 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}')) { ... }