Config-Model

 view release on metacpan or  search on metacpan

lib/Config/Model.pm  view on Meta::CPAN

The class elements (usually matching configuration parameters)

=back

Each element specifies:

=over

=item *

First and foremost, the type of the element (mostly C<leaf>, or C<node>)

=item *

The properties of each element (boundaries, check, integer or string,
enum like type ...)

=item *

The default values of parameters (if any)

=item *

Whether the parameter is mandatory

=item *

On-line help (for each parameter or value of parameter)

=back

L<Config::Model::Node/"Configuration class declaration"> provides more
details on how to declare a configuration class.

Example:

 $ cat lib/Config/Model/models/Popcon.pl
 use strict;
 use warnings;

 return [
   {
     'name' => 'PopCon',
     'author' => ['Dominique Dumont'],
     'copyright' => ['2010,2011 Dominique Dumont'],
     'license' => 'LGPL2',
     'element' => [
       'PARTICIPATE',
       {
         'description' => 'If you don\'t want to participate [...]',
         'type' => 'leaf',
         'upstream_default' => '0',
         'value_type' => 'boolean',
         'write_as' => ['no', 'yes']
       },
       'ENCRYPT',
       {
         'choice' => ['no', 'maybe', 'yes'],
         'description' => 'encrypt popcon submission.',
         'help' => {
           'maybe' => 'encrypt if gpg is available',
           'yes' => 'try to encrypt and fail if gpg is not available'
         },
         'summary' => 'support for encrypted submissions',
         'type' => 'leaf',
         'upstream_default' => 'no',
         'value_type' => 'enum'
       },
       # [etc ...]
     ],
     'rw_config' => {
       'backend' => 'ShellVar',
       'config_dir' => '/etc',
       'file' => 'popularity-contest.conf'
     }
   }
 ];

=head1 Configuration instance methods

A configuration instance is created from a model and is the starting
point of a configuration tree.

=head2 instance

An instance must be created with a model name (using the root class
name) or an application name (as shown by "L<cme> C<list>" command).

For example:

 my $model = Config::Model->new() ;
 $model->instance( application => 'approx');

Or:

 my $model = Config::Model->new() ;
 # note that the model class is slightly different compared to
 # application name
 $model->instance( root_class_name => 'Approx');

A custom configuration class can also be used with C<root_class_name> parameter:

 my $model = Config::Model->new() ;
 # create_config_class is described below
 $model ->create_config_class (
   name => "SomeRootClass",
   element => [ ...  ]
 ) ;

 # instance name is 'default'
 my $inst = $model->instance (root_class_name => 'SomeRootClass');

You can create several separated instances from a model using
C<name> option:

 # instance name is 'default'
 my $inst = $model->instance (
   root_class_name => 'SomeRootClass',
   name            => 'test1'
 );

Usually, model files are loaded automatically using a path matching



( run in 0.872 second using v1.01-cache-2.11-cpan-df04353d9ac )