NAME
Config::Model::AutoRead - Load on demand base class for configuration node
SYNOPSIS
$model->create_config_class
(
config_class_name => 'OneAutoReadConfigClass',
read_config => [ 'cds', { class => 'ProcessRead' , function => 'read_it'} ],
write_config => 'cds';
config_dir => '/etc/my_config_dir',
element => ...
) ;
DESCRIPTION
This class provides a way to read on demand the configuration informations.
In other words, when a node object is created, all the configuration information are read during creation.
This feature is also useful if you want to read configuration class declarations at run time. (For instance in a /etc
directory like /etc/config_model.d
). In this case, each configuration class must specify how to read and write configuration information.
This read/write features can be:
Config dump string (cds). I.e. a string that describes the content of a configuration tree. See Config::Model::Dumper.
XML. Not yet implemented (ask the author if you're interested)
Any format when the user provides a dedicated class and function to read and load the configuration tree.
When read, the object registers itself to the instance. Then the user can call the write_back
method on the instance (See Config::Model::Instance) to write all configuration informations.
Configuration class with auto read or auto write
read and write specification
A configuration class will be declared with optional read
or write
parameters:
read_config => [ 'cds',
read => { class => 'Bar' , function => 'read_it'}, ]
write_config => 'cds';
The various read
method will be tried in order specified. When a read operation is successful, the remaining read methods will be skipped.
In the example above, AutoRead
will first try to load the "dump tree string" as defined in Config::Model::Dumper. If successful, the configuration tree is loaded and the second method is skippped.
If loading the cds
file fails, the following method is tried by calling read_it
function from package Bar
.
The second function will be called with these parameters:
(object => config_tree_root, conf_dir => config_file_location )
When necessary (or required by the user), all configuration informations are written back using all the write method passed.
In the example above, only a cds
file is written. The example above is an example of a graceful migration from a customized format to a cds
format.
To read and write only customized files :
read_config => { class => 'Bar' , function => 'read_it'},
write_config => { class => 'Bar' , function => 'write_it'};
To read and write only cds files :
read_config => 'cds',
write_config => 'cds' ;
To migrate from custom format to xml:
read_config => [ 'xml', { class => 'Bar' , function => 'read_it'} ],
write_config => 'xml';
To migrate from an old format to a new format:
read_config => [ { class => 'OldFormat' , function => 'old_read'} ,
{ class => 'NewFormat' , function => 'new_read'} ],
write_config => [ { class => 'NewFormat' , function => 'write' } ],
read write directory
You must also specify where to read or write configuration information. These informations can be read or written in the same directory :
conf_dir => '/etc/my_config_dir',
Or configuration informations can be read from one directory and written in another directory:
read_config_dir => '/etc/old_config_dir',
write_config_dir => '/etc/new_config_dir',
AUTHOR
Dominique Dumont, domi@komarr.grenoble.hp.com
SEE ALSO
Config::Model, Config::Model::Instance, Config::Model::Node, Config::Model::Dumper
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 140:
=end comment without matching =begin. (Stack: [empty])