.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Config::Model::BackendMgr 3pm" .TH Config::Model::BackendMgr 3pm "2023-08-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Config::Model::BackendMgr \- Load configuration node on demand .SH "VERSION" .IX Header "VERSION" version 2.153 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& # 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 => \*(Aqleaf\*(Aq, \& value_type => \*(Aqstring\*(Aq \& }, \& ] \& ); \& \& $model\->create_config_class( \& name => "MyClass", \& \& # rw_config spec is used by Config::Model::BackendMgr \& rw_config => { \& backend => \*(Aqyaml\*(Aq, \& config_dir => \*(Aq/tmp/\*(Aq, \& file => \*(Aqmy_class.yml\*(Aq, \& auto_create => 1, \& }, \& \& element => [ \& [qw/foo bar/] => { \& type => \*(Aqleaf\*(Aq, \& value_type => \*(Aqstring\*(Aq \& }, \& hash_of_nodes => { \& type => \*(Aqhash\*(Aq, # hash id \& index_type => \*(Aqstring\*(Aq, \& cargo => { \& type => \*(Aqnode\*(Aq, \& config_class_name => \*(AqFoo\*(Aq \& }, \& }, \& ], \& ); \& \& my $inst = $model\->instance( root_class_name => \*(AqMyClass\*(Aq ); \& \& my $root = $inst\->config_root; \& \& # put data \& my $steps = \*(Aqfoo=FOO hash_of_nodes:fr foo=bonjour \- \& hash_of_nodes:en foo=hello \*(Aq; \& $root\->load( steps => $steps ); \& \& $inst\->write_back; \& \& # now look at file /tmp/my_class.yml .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class provides a way to specify how to load or store configuration data within the model. .PP 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. .PP This load/store can be done with different backends: .IP "\(bu" 4 Any of the \f(CW\*(C`Config::Model::Backend::*\*(C'\fR classes available on your system. For instance \f(CW\*(C`Config::Model::Backend::Yaml\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`cds_file\*(C'\fR: Config dump string (cds) in a file. I.e. a string that describes the content of a configuration tree is loaded from or saved in a text file. This format is defined by this project. See \&\*(L"load string syntax\*(R" in Config::Model::Loader. .IP "\(bu" 4 \&\f(CW\*(C`perl_file\*(C'\fR: Perl data structure (perl) in a file. See Config::Model::DumpAsData for details on the data structure. Now handled by Config::Model::Backend::PerlFile .PP When needed, \f(CW\*(C`write_back\*(C'\fR method can be called on the instance (See Config::Model::Instance) to store back all configuration information. .SH "Backend specification" .IX Header "Backend specification" The backend specification is provided as an attribute of a Config::Model::Node specification. These attributes are optional: A node without \f(CW\*(C`rw_config\*(C'\fR attribute must rely on another node to read or save its data. .PP When needed (usually for the root node), the configuration class is declared with a \f(CW\*(C`rw_config\*(C'\fR parameter which specifies the read/write backend configuration. .SS "Parameters available for all backends" .IX Subsection "Parameters available for all backends" The following parameters are accepted by all backends: .IP "config_dir" 4 .IX Item "config_dir" Specify configuration directory. This parameter is optional as the directory can be hardcoded in the backend class. \f(CW\*(C`config_dir\*(C'\fR beginning with '\f(CW\*(C`~\*(C'\fR' is munged so \f(CW\*(C`~\*(C'\fR is replaced by \f(CW\*(C`File::HomeDir\->my_data\*(C'\fR. See File::HomeDir for details. .IP "file" 4 .IX Item "file" Specify configuration file name (without the path). This parameter is optional as the file name can be hardcoded in the backend class. .Sp The configuration file name can be specified with \f(CW&index\fR keyword when a backend is associated to a node contained in a hash. For instance, with \f(CW\*(C`file\*(C'\fR set to \f(CW\*(C`&index.conf\*(C'\fR: .Sp .Vb 5 \& service # hash element \& foo # hash index \& nodeA # values of nodeA are stored in foo.conf \& bar # hash index \& nodeB # values of nodeB are stored in bar.conf .Ve .Sp Likewise, the keyword \f(CW&element\fR can be used to specify the file name. For instance, with \f(CW\*(C`file\*(C'\fR set to \f(CW\*(C`&element\-&index.conf\*(C'\fR: .Sp .Vb 5 \& service # hash element \& foo # hash index \& nodeA # values of nodeA are stored in service.foo.conf \& bar # hash index \& nodeB # values of nodeB are stored in service.bar.conf .Ve .IP "file_mode" 4 .IX Item "file_mode" \&\f(CW\*(C`file_mode\*(C'\fR parameter can be used to set the mode of the written file(s). \f(CW\*(C`file_mode\*(C'\fR value can be in any form supported by \&\*(L"chmod\*(R" in Path::Tiny. Example: .Sp .Vb 3 \& file_mode => 0664, \& file_mode => \*(Aq0664\*(Aq, \& file_mode => \*(Aqg+w\*(Aq .Ve .IP "os_config_dir" 4 .IX Item "os_config_dir" Specify alternate location of a configuration directory depending on the \s-1OS\s0 (as returned by \f(CW$^O\fR, see \*(L"\s-1PLATFORMS\*(R"\s0 in perlport). For instance: .Sp .Vb 2 \& config_dir => \*(Aq/etc/ssh\*(Aq, \& os_config_dir => { darwin => \*(Aq/etc\*(Aq } .Ve .IP "default_layer" 4 .IX Item "default_layer" Optional. Specifies where to find a global configuration file that specifies default values. For instance, this is used by OpenSSH to specify a global configuration file (\f(CW\*(C`/etc/ssh/ssh_config\*(C'\fR) that is overridden by user's file: .Sp .Vb 5 \& default_layer => { \& os_config_dir => { \*(Aqdarwin\*(Aq => \*(Aq/etc\*(Aq }, \& config_dir => \*(Aq/etc/ssh\*(Aq, \& file => \*(Aqssh_config\*(Aq \& } .Ve .Sp Only the 3 above parameters can be specified in \f(CW\*(C`default_layer\*(C'\fR. .IP "auto_create" 4 .IX Item "auto_create" By default, an exception is thrown if no read was successful. This behavior can be overridden by specifying \&\f(CW\*(C`auto_create => 1\*(C'\fR in one of the backend specification. For instance: .Sp .Vb 6 \& rw_config => { \& backend => \*(AqIniFile\*(Aq, \& config_dir => \*(Aq/tmp\*(Aq, \& file => \*(Aqfoo.conf\*(Aq, \& auto_create => 1 \& }, .Ve .Sp Setting \f(CW\*(C`auto_create\*(C'\fR to 1 is necessary to create a configuration from scratch .IP "auto_delete" 4 .IX Item "auto_delete" Delete configuration files that contains no data. (default is to leave an empty file) .SS "Config::Model::Backend::* backends" .IX Subsection "Config::Model::Backend::* backends" Specify the backend name and the parameters of the backend defined in their documentation. .PP For instance: .PP .Vb 5 \& rw_config => { \& backend => \*(Aqyaml\*(Aq, \& config_dir => \*(Aq/tmp/\*(Aq, \& file => \*(Aqmy_class.yml\*(Aq, \& }, .Ve .PP See Config::Model::Backend::Yaml for more details for this backend. .SS "Your own backend" .IX Subsection "Your own backend" You can also write a dedicated backend. See How to write your own backend for details. .SH "Test setup" .IX Header "Test setup" By default, configurations files are read from the directory specified by \f(CW\*(C`config_dir\*(C'\fR parameter specified in the model. You may override the \&\f(CW\*(C`root\*(C'\fR directory for test. .SH "Methods" .IX Header "Methods" .SS "support_annotation" .IX Subsection "support_annotation" Returns 1 if at least the backend supports read and write annotations (aka comments) in the configuration file. .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont, (ddumont at cpan dot org) .SH "SEE ALSO" .IX Header "SEE ALSO" Config::Model, Config::Model::Instance, Config::Model::Node, Config::Model::Dumper .SH "AUTHOR" .IX Header "AUTHOR" Dominique Dumont .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2005\-2022 by Dominique Dumont. .PP This is free software, licensed under: .PP .Vb 1 \& The GNU Lesser General Public License, Version 2.1, February 1999 .Ve