3.3. EBox::GConfModule

eBox uses GConf to store its configuration, the development framework provides a wrapper around the original perl bindings. GConf gives us an easy API for storing and retrieving typed configuration values organized hierarchically. It also lets us define limited schemas for certain configuration keys, setting their type and default values.

The development framework defines a wrapper around the GConf API that provides some extra features. The wrapper is implemented as child class for EBox::Module, so all modules that want to use GConf inherit from EBox::GConfModule. Its children automatically get these features:

This is a list of the most important methods in EBox::GConfModule:

all_dirs

Given a key it returns all directories within.

all_dirs_base

Given a key it returns all directories within, removing any leading directory component.

all_entries

Given a key it returns all entries within. Entries are all those keys which are not directories, hence they contain a value.

all_entries_base

Given a key it returns all entries within, removing any leading directory component. Entries are all those keys which are not directories, hence they contain a value.

array_from_dir

Given a key it returns an array using a hash reference to contain in each element the directories under the key. Also, the hash contains the key _dir which tells you the directory's name.

dir_exists

Given a key referencing a directory it returns true if it exists.

get_bool

Returns the value of a boolean key.

get_int

Returns the value of a integer key.

get_list

Returns an array containing the list referenced by the key.

get_string

Returns the value of a string key.

get_unique_id

It generates a unique random identifier with a leading prefix in the root of the module's namespace, if directory is passed, it will be added to the path. Note that it does not create the entry, it just returns a unique identifier, so it is up to you to create the proper entry.

hash_from_dir

It returns a hash containing all the entries in the directory referenced by the key.

isReadOnly

It returns true if the current EBox::GConfModule instance you are accessing is read-only.

makeBackup

It dumps your current configuration to file.

restoreBackup

It restores the last backup.

revokeConfig

All changes done since your first write or delete will be dismissed.

set_bool

It sets a key with a boolean value.

set_int

It sets a key with an integer value.

set_list

It sets a list of typevalues in value.

set_string

It sets values of type in key.

Let's see some examples from the above functions.

Example 3.3. Setting a string key

 $self->set_string("printers/x4235/name", "fooprinter"); 

Example 3.4. Setting a string list

$self->set_list('foo/foolist', 'string', ['foo', 'bar']);

Example 3.5. Getting and using a unique identifier

my $id = $self->get_unique_id('p', 'printers');
$self->set_string("printers/$id/name", $name);
$self->set_bool("printers/$id/configured", undef);