1Config::Model::Backend:U:sYearmlC(o3n)tributed Perl DocuCmoennftiagt:i:oMnodel::Backend::Yaml(3)
2
3
4

NAME

6       Config::Model::Backend::Yaml - Read and write config as a YAML data
7       structure
8

VERSION

10       version 2.129
11

SYNOPSIS

13        use Config::Model ;
14        use Data::Dumper ;
15
16        # define configuration tree object
17        my $model = Config::Model->new ;
18        $model ->create_config_class (
19           name => "MyClass",
20           element => [
21               [qw/foo bar/] => {
22                   type => 'leaf',
23                   value_type => 'string'
24               },
25               baz => {
26                   type => 'hash',
27                   index_type => 'string' ,
28                   cargo => {
29                       type => 'leaf',
30                       value_type => 'string',
31                   },
32               },
33           ],
34         rw_config  => {
35           backend => 'yaml',
36           config_dir => '/tmp',
37           file  => 'foo.yml',
38           auto_create => 1,
39         }
40        ) ;
41
42        my $inst = $model->instance(root_class_name => 'MyClass' );
43
44        my $root = $inst->config_root ;
45
46        my $steps = 'foo=yada bar="bla bla" baz:en=hello
47                    baz:fr=bonjour baz:hr="dobar dan"';
48        $root->load( steps => $steps ) ;
49        $inst->write_back ;
50
51       Now, "/tmp/foo.yml" contains:
52
53        ---
54        bar: bla bla
55        baz:
56          en: hello
57          fr: bonjour
58          hr: dobar dan
59        foo: yada
60

DESCRIPTION

62       This module is used directly by Config::Model to read or write the
63       content of a configuration tree written with YAML syntax in
64       "Config::Model" configuration tree.
65
66       Note:
67
68       ·   Undefined values are skipped for list element. I.e. if a list
69           element contains "('a',undef,'b')", the data structure contains
70           'a','b'.
71
72       ·   YAML file is not created (and may be deleted) when no data is to be
73           written.
74
75   Class with only one hash element
76       If the root node contains a single hash or list element, only the
77       content of this hash is written in a YAML file.
78
79       For example, if a class contains:
80
81             element => [
82               baz => {
83                   type => 'hash',
84                   index_type => 'string' ,
85                   cargo => {
86                       type => 'leaf',
87                       value_type => 'string',
88                   },
89               },
90
91       If the configuration is loaded with:
92
93        $root->load("baz:one=un baz:two=deux")
94
95       Then the written YAML file does not show "baz":
96
97        ---
98        one: un
99        two: deux
100
101       Likewise, a YAML file for a class with a single list "baz" element
102       would be written with:
103
104        ---
105        - un
106        - deux
107

backend parameter

109   yaml_class
110       By default, this module uses YAML::Tiny. This module has the advantage
111       of being light and secure <https://github.com/ingydotnet/yaml-libyaml-
112       pm/issues/45>.  No Perl object can be created with YAML tags so
113       YAML::Tiny can be used with YAML files coming from unutrusted sources.
114
115       On the other hand, YAML::Tiny does not support boolean values: it
116       cannot write "true" and "false" as plain scalar. "true" and "false" are
117       quoted and are not of type boolean from YAML point of view.
118
119       If this is a problem for your configuration files, you can use YAML
120       module which writes "true" and "false" without quotes.
121

CONSTRUCTOR

123   new
124       Parameters: "( node => $node_obj, name => 'yaml' )"
125
126       Inherited from Config::Model::Backend::Any. The constructor is called
127       by Config::Model::BackendMgr.
128
129   read
130       Read YAML file and load into $node_obj tree.
131
132       When a file is read, "read" returns 1.
133
134   write
135       Write YAML File using $node_obj data.
136
137       "write" returns 1.
138

AUTHOR

140       Dominique Dumont, (ddumont at cpan dot org)
141

SEE ALSO

143       Config::Model, Config::Model::BackendMgr, Config::Model::Backend::Any,
144

AUTHOR

146       Dominique Dumont
147
149       This software is Copyright (c) 2005-2018 by Dominique Dumont.
150
151       This is free software, licensed under:
152
153         The GNU Lesser General Public License, Version 2.1, February 1999
154
155
156
157perl v5.28.1                      2018-12-07   Config::Model::Backend::Yaml(3)
Impressum