Config::Model::AutoRead - Load on demand base class for configuration node


NAME

Config::Model::AutoRead - Load on demand base class for configuration node


SYNOPSIS

  # top level config file name matches instance name
  $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 => ...
     ) ;
  # config data will be written in /etc/my_config_dir/foo.cds
  my $instance = $model->instance(instance_name => 'foo') ;


DESCRIPTION

This class provides a way to specify how to read or write configuration data within the model (instead of writing dedicated perl code).

In other words, when a node object is created, all the configuration information are read during creation of the node.

This read/write can be done with:

When read, the object registers itself to the instance. Then the user can call the write_back method on the instance (See the Config::Model::Instance manpage) to write all configuration informations.

Built-in read write format

Currently, this class supports the following built-in formats:

cds

Config dumpt string. See the Config::Model::Dumper manpage.

ini

Ini files written by the Config::Tiny manpage.


Limitations depending on storage

Some storage system will limit the structure of the model you can map to the file.

Ini files limitation

Structure of the Config::Model must be very simple. Either:


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.

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. But, both custom format and cds file are tried, this example is also an example of a graceful migration from a customized format to a cds format.

You can choose also to read and write only customized files :

  read_config  => { class => 'Bar' ,  function => 'read_it'},
  write_config => { class => 'Bar' ,  function => 'write_it'};

Or to read and write only cds files :

  read_config  => 'cds', 
  write_config => 'cds' ;

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 :

  config_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, (ddumont at cpan dot org)


SEE ALSO

the Config::Model manpage, the Config::Model::Instance manpage, the Config::Model::Node manpage, the Config::Model::Dumper manpage

 Config::Model::AutoRead - Load on demand base class for configuration node