|
NAMEConfig::Model::BackendMgr - Load configuration node on demandVERSIONversion 2.149SYNOPSIS# Use BackendMgr to write data in Yaml file # This example requires Config::Model::Backend::Yaml which is now # shipped outside of Config::Model. Please get it on CPAN use Config::Model; # define configuration tree object my $model = Config::Model->new; $model->create_config_class( name => "Foo", element => [ [qw/foo bar/] => { type => 'leaf', value_type => 'string' }, ] ); $model->create_config_class( name => "MyClass", # rw_config spec is used by Config::Model::BackendMgr rw_config => { backend => 'yaml', config_dir => '/tmp/', file => 'my_class.yml', auto_create => 1, }, element => [ [qw/foo bar/] => { type => 'leaf', value_type => 'string' }, hash_of_nodes => { type => 'hash', # hash id index_type => 'string', cargo => { type => 'node', config_class_name => 'Foo' }, }, ], ); my $inst = $model->instance( root_class_name => 'MyClass' ); my $root = $inst->config_root; # put data my $steps = 'foo=FOO hash_of_nodes:fr foo=bonjour - hash_of_nodes:en foo=hello '; $root->load( steps => $steps ); $inst->write_back; # now look at file /tmp/my_class.yml DESCRIPTIONThis class provides a way to specify how to load or store configuration data within the model.With these specifications, all configuration information is read during creation of a node (which triggers the creation of a backend manager object) and written back when write_back method is called either on the instance. This load/store can be done with different backends:
When needed, "write_back" method can be called on the instance (See Config::Model::Instance) to store back all configuration information. Backend specificationThe backend specification is provided as an attribute of a Config::Model::Node specification. These attributes are optional: A node without "rw_config" attribute must rely on another node to read or save its data.When needed (usually for the root node), the configuration class is declared with a "rw_config" parameter which specifies the read/write backend configuration. Parameters available for all backendsThe following parameters are accepted by all backends:
Config::Model::Backend::* backendsSpecify the backend name and the parameters of the backend defined in their documentation.For instance: rw_config => { backend => 'yaml', config_dir => '/tmp/', file => 'my_class.yml', }, See Config::Model::Backend::Yaml for more details for this backend. Your own backendYou can also write a dedicated backend. See How to write your own backend for details.Test setupBy default, configurations files are read from the directory specified by "config_dir" parameter specified in the model. You may override the "root" directory for test.Methodssupport_annotationReturns 1 if at least the backend supports read and write annotations (aka comments) in the configuration file.AUTHORDominique Dumont, (ddumont at cpan dot org)SEE ALSOConfig::Model, Config::Model::Instance, Config::Model::Node, Config::Model::DumperAUTHORDominique DumontCOPYRIGHT AND LICENSEThis software is Copyright (c) 2005-2022 by Dominique Dumont.This is free software, licensed under: The GNU Lesser General Public License, Version 2.1, February 1999
Visit the GSP FreeBSD Man Page Interface. |