1Config::Model::DumpAsDaUtsae(r3)Contributed Perl DocumenCtoantfiiogn::Model::DumpAsData(3)
2
3
4

NAME

6       Config::Model::DumpAsData - Dump configuration content as a perl data
7       structure
8

VERSION

10       version 2.152
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           ],
35        ) ;
36
37        my $inst = $model->instance(root_class_name => 'MyClass' );
38
39        my $root = $inst->config_root ;
40
41        # put some data in config tree the hard way
42        $root->fetch_element('foo')->store('yada') ;
43        $root->fetch_element('bar')->store('bla bla') ;
44        $root->fetch_element('baz')->fetch_with_id('en')->store('hello') ;
45
46        # put more data the easy way
47        my $steps = 'baz:fr=bonjour baz:hr="dobar dan"';
48        $root->load( steps => $steps ) ;
49
50        print Dumper($root->dump_as_data);
51        # $VAR1 = {
52        #         'bar' => 'bla bla',
53        #         'baz' => {
54        #                    'en' => 'hello',
55        #                    'fr' => 'bonjour',
56        #                    'hr' => 'dobar dan'
57        #                  },
58        #         'foo' => 'yada'
59        #       };
60

DESCRIPTION

62       This module is used directly by Config::Model::Node to dump the content
63       of a configuration tree in perl data structure.
64
65       The perl data structure is a hash of hash. Only CheckList content is
66       stored in an array ref.
67
68       User can pass a sub reference to apply to values of boolean type. This
69       sub can be used to convert the value to an object representing a
70       boolean like boolean. (since 2.129)
71
72       Note that undefined values are skipped for list element. I.e. if a list
73       element contains "('a',undef,'b')", the data structure then contains
74       'a','b'.
75

CONSTRUCTOR

77   new
78       No parameter. The constructor should be used only by
79       Config::Model::Node.
80

Methods

82   dump_as_data
83       Return a perl data structure
84
85       Parameters are:
86
87       node
88           Reference to a Config::Model::Node object. Mandatory
89
90       full_dump
91           Also dump default values in the data structure. Useful if the
92           dumped configuration data is used by the application. This
93           parameter is deprecated in favor of mode parameter.
94
95       mode
96           Note that "mode" parameter is also accepted and overrides
97           "full_dump" parameter. See "fetch" in Config::Model::Value for
98           details on "mode".
99
100       skip_auto_write
101           Skip node that have a "perl write" capability in their model. See
102           Config::Model::BackendMgr.
103
104           This option must be used when using DumpAsData: to write back
105           configuration data. When a configuration model contains several
106           backends (one at the tree root and others in tree nodes), setting
107           this option ensure that the "root" configuration file does not
108           contain data duplicated in configuration file of others tree nodes.
109
110       auto_vivify
111           Scan and create data for nodes elements even if no actual data was
112           stored in them. This may be useful to trap missing mandatory
113           values.
114
115       ordered_hash_as_list
116           By default, ordered hash (i.e. the order of the keys are important)
117           are dumped as Perl list. This is the faster way to dump such hashed
118           while keeping the key order. But it's the less readable way.
119
120           When this parameter is 1 (default), the ordered hash is dumped as a
121           list:
122
123             my_hash => [ A => 'foo', B => 'bar', C => 'baz' ]
124
125           When this parameter is set as 0, the ordered hash is dumped with a
126           special key that specifies the order of keys. E.g.:
127
128             my_hash => {
129              __my_hash_order => [ 'A', 'B', 'C' ] ,
130              B => 'bar', A => 'foo', C => 'baz'
131             }
132
133       to_boolean
134           Sub reference to map a value of type boolean to a boolean class
135           (since 2.129). For instance:
136
137            to_boolean => sub { boolean($_[0]); }
138
139           Default is "sub { return $_[0] }"
140

Methods

142   dump_annotations_as_pod
143       Return a string formatted in pod (See perlpod) with the annotations.
144
145       Parameters are:
146
147       node
148           Reference to a Config::Model::Node object. Mandatory
149
150       check_list
151           Yes, no or skip
152

AUTHOR

154       Dominique Dumont, (ddumont at cpan dot org)
155

SEE ALSO

157       Config::Model,Config::Model::Node,Config::Model::ObjTreeScanner
158

AUTHOR

160       Dominique Dumont
161
163       This software is Copyright (c) 2005-2022 by Dominique Dumont.
164
165       This is free software, licensed under:
166
167         The GNU Lesser General Public License, Version 2.1, February 1999
168
169
170
171perl v5.36.0                      2023-01-20      Config::Model::DumpAsData(3)
Impressum