1Config::Model::BackendMUgsre(r3)Contributed Perl DocumenCtoantfiiogn::Model::BackendMgr(3)
2
3
4

NAME

6       Config::Model::BackendMgr - Load configuration node on demand
7

VERSION

9       version 2.129
10

SYNOPSIS

12        # Use BackendMgr to write data in Yaml file
13        use Config::Model;
14
15        # define configuration tree object
16        my $model = Config::Model->new;
17        $model->create_config_class(
18           name    => "Foo",
19           element => [
20               [qw/foo bar/] => {
21                   type       => 'leaf',
22                   value_type => 'string'
23               },
24           ]
25        );
26
27        $model->create_config_class(
28           name => "MyClass",
29
30           # rw_config spec is used by Config::Model::BackendMgr
31           rw_config => {
32               backend     => 'yaml',
33               config_dir  => '/tmp/',
34               file        => 'my_class.yml',
35               auto_create => 1,
36           },
37
38           element => [
39               [qw/foo bar/] => {
40                   type       => 'leaf',
41                   value_type => 'string'
42               },
43               hash_of_nodes => {
44                   type       => 'hash',     # hash id
45                   index_type => 'string',
46                   cargo      => {
47                       type              => 'node',
48                       config_class_name => 'Foo'
49                   },
50               },
51           ],
52        );
53
54        my $inst = $model->instance( root_class_name => 'MyClass' );
55
56        my $root = $inst->config_root;
57
58        # put data
59        my $steps = 'foo=FOO hash_of_nodes:fr foo=bonjour -
60          hash_of_nodes:en foo=hello ';
61        $root->load( steps => $steps );
62
63        $inst->write_back;
64
65        # now look at file /tmp/my_class.yml
66

DESCRIPTION

68       This class provides a way to specify how to load or store configuration
69       data within the model.
70
71       With these specifications, all configuration information is read during
72       creation of a node (which triggers the creation of a backend manager
73       object) and written back when write_back method is called (either on
74       the node or on this backend manager).
75
76       This load/store can be done with different backends:
77
78       ·   Any of the "Config::Model::Backend::*" classes available on your
79           system.  For instance "Config::Model::Backend::Yaml".
80
81       ·   "cds_file": Config dump string (cds) in a file. I.e. a string that
82           describes the content of a configuration tree is loaded from or
83           saved in a text file. This format is defined by this project. See
84           "load string syntax" in Config::Model::Loader.
85
86       ·   "perl_file": Perl data structure (perl) in a file. See
87           Config::Model::DumpAsData for details on the data structure. Now
88           handled by Config::Model::Backend::PerlFile
89
90       When needed, "write_back" method can be called on the instance (See
91       Config::Model::Instance) to store back all configuration information.
92

Backend specification

94       The backend specification is provided as an attribute of a
95       Config::Model::Node specification. These attributes are optional: A
96       node without "rw_config" attribute must rely on another node to read or
97       save its data.
98
99       When needed (usually for the root node), the configuration class is
100       declared with a "rw_config" parameter which specifies the read/write
101       backend configuration.
102
103   Parameters available for all backends
104       The following parameters are accepted by all backends:
105
106       config_dir
107           Specify configuration directory. This parameter is optional as the
108           directory can be hardcoded in the backend class. "config_dir"
109           beginning with '"~"' is munged so "~" is replaced by
110           "File::HomeDir->my_data".  See File::HomeDir for details.
111
112       file
113           Specify configuration file name (without the path). This parameter
114           is optional as the file name can be hardcoded in the backend class.
115
116           The configuration file name can be specified with &index keyword
117           when a backend is associated to a node contained in a hash. For
118           instance, with "file" set to "&index.conf":
119
120            service    # hash element
121              foo      # hash index
122                nodeA  # values of nodeA are stored in foo.conf
123              bar      # hash index
124                nodeB  # values of nodeB are  stored in bar.conf
125
126           Likewise, the keyword &element can be used to specify the file
127           name. For instance, with "file" set to "&element-&index.conf":
128
129            service    # hash element
130              foo      # hash index
131                nodeA  # values of nodeA are stored in service.foo.conf
132              bar      # hash index
133                nodeB  # values of nodeB are  stored in service.bar.conf
134
135       file_mode
136           "file_mode" parameter can be used to set the mode of the written
137           file(s). "file_mode" value can be in any form supported by "chmod"
138           in Path::Tiny. Example:
139
140             file_mode => 0664,
141             file_mode => '0664',
142             file_mode => 'g+w'
143
144       os_config_dir
145           Specify alternate location of a configuration directory depending
146           on the OS (as returned by $^O, see "PLATFORMS" in perlport).  For
147           instance:
148
149            config_dir => '/etc/ssh',
150            os_config_dir => { darwin => '/etc' }
151
152       default_layer
153           Optional. Specifies where to find a global configuration file that
154           specifies default values. For instance, this is used by OpenSSH to
155           specify a global configuration file ("/etc/ssh/ssh_config") that is
156           overridden by user's file:
157
158            default_layer => {
159               os_config_dir => { 'darwin' => '/etc' },
160               config_dir    => '/etc/ssh',
161               file          => 'ssh_config'
162            }
163
164           Only the 3 above parameters can be specified in "default_layer".
165
166       auto_create
167           By default, an exception is thrown if no read was successful. This
168           behavior can be overridden by specifying "auto_create => 1" in one
169           of the backend specification. For instance:
170
171            rw_config  => {
172                backend => 'IniFile',
173                config_dir => '/tmp',
174                file  => 'foo.conf',
175                auto_create => 1
176            },
177
178           Setting "auto_create" to 1 is necessary to create a configuration
179           from scratch
180
181       auto_delete
182           Delete configuration files that contains no data. (default is to
183           leave an empty file)
184
185   Config::Model::Backend::* backends
186       Specify the backend name and the parameters of the backend defined in
187       their documentation.
188
189       For instance:
190
191        rw_config => {
192            backend     => 'yaml',
193            config_dir  => '/tmp/',
194            file        => 'my_class.yml',
195        },
196
197       See Config::Model::Backend::Yaml for more details for this backend.
198
199   Your own backend
200       You can also write a dedicated backend. See How to write your own
201       backend for details.
202

Test setup

204       By default, configurations files are read from the directory specified
205       by "config_dir" parameter specified in the model. You may override the
206       "root" directory for test.
207

Methods

209   support_annotation
210       Returns 1 if at least the backend supports read and write annotations
211       (aka comments) in the configuration file.
212

AUTHOR

214       Dominique Dumont, (ddumont at cpan dot org)
215

SEE ALSO

217       Config::Model, Config::Model::Instance, Config::Model::Node,
218       Config::Model::Dumper
219

AUTHOR

221       Dominique Dumont
222
224       This software is Copyright (c) 2005-2018 by Dominique Dumont.
225
226       This is free software, licensed under:
227
228         The GNU Lesser General Public License, Version 2.1, February 1999
229
230
231
232perl v5.28.1                      2018-12-07      Config::Model::BackendMgr(3)
Impressum