1Config::Model::WarpedNoUdsee(r3pCmo)ntributed Perl DocumCeonntfaitgi:o:nModel::WarpedNode(3pm)
2
3
4

NAME

6       Config::Model::WarpedNode - Node that change config class properties
7

VERSION

9       version 2.153
10

SYNOPSIS

12        use Config::Model;
13
14        my $model = Config::Model->new;
15        foreach (qw/X Y/) {
16           $model->create_config_class(
17               name    => "Class$_",
18               element => [ foo => {qw/type leaf value_type string/} ]
19           );
20        }
21        $model->create_config_class(
22           name => "MyClass",
23
24           element => [
25               master_switch => {
26                   type       => 'leaf',
27                   value_type => 'enum',
28                   choice     => [qw/cX cY/]
29               },
30
31               'a_warped_node' => {
32                   type   => 'warped_node',
33                   warp => }
34                      follow => { ms => '! master_switch' },
35                      rules  => [
36                          '$ms eq "cX"' => { config_class_name => 'ClassX' },
37                          '$ms eq "cY"' => { config_class_name => 'ClassY' },
38                      ]
39                   }
40               },
41           ],
42        );
43
44        my $inst = $model->instance(root_class_name => 'MyClass' );
45        my $root = $inst->config_root ;
46
47        print "Visible elements: ",join(' ',$root->get_element_name),"\n" ;
48        # Visible elements: master_switch
49
50        $root->load( steps => 'master_switch=cX' );
51        print "Visible elements: ",join(' ',$root->get_element_name),"\n" ;
52        # Visible elements: master_switch a_warped_node
53
54        my $node = $root->grab('a_warped_node') ;
55        print "a_warped_node class: ",$node->config_class_name,"\n" ;
56        # a_warped_node class: ClassX
57
58        $root->load( steps => 'master_switch=cY' );
59        print "a_warped_node class: ",$node->config_class_name,"\n" ;
60        # a_warped_node class: ClassY
61

DESCRIPTION

63       This class provides a way to change dynamically the configuration class
64       (or some other properties) of a node. The changes are done according to
65       the model declaration.
66
67       This declaration specifies one (or several) leaf in the configuration
68       tree that triggers the actual property change of the warped node. This
69       leaf is also referred as warp master.
70
71       When the warp master(s) value(s) changes, "WarpedNode" creates an
72       instance of the new class required by the warp master.
73
74       If the morph parameter is set, the values held by the old object are
75       (if possible) copied to the new instance of the object using copy_from
76       method.
77
78       Warped node can alter the following properties:
79
80        config_class_name
81        level
82

Constructor

84       "WarpedNode" should not be created directly.
85

Warped node model declaration

87   Parameter overview
88       A warped node must be declared with the following parameters:
89
90       type
91           Always set to "warped_node".
92
93       follow
94           Grab string leading to the "Config::Model::Value" warp master.  See
95           "Warp follow argument" in Config::Model::Warper for details.
96
97       morph
98           boolean. If 1, "WarpedNode" tries to recursively copy the value
99           from the old object to the new object using copy_from method.  When
100           a copy is not possible, undef values are assigned to object
101           elements.
102
103       rules
104           Hash or array ref that specify the property change rules according
105           to the warp master(s) value(s).  See "Warp rules argument" in
106           Config::Model::Warper for details on how to specify the warp master
107           values (or combination of values).
108
109   Effect declaration
110       For a warped node, the effects are declared with these parameters:
111
112       config_class_name
113               When requested by the warp master,the "WarpedNode" creates a
114               new object of the type specified by this parameter:
115
116                 XZ => { config_class_name => 'SlaveZ' }
117
118               Instead of a string, you can an array ref which contains the
119               class name and constructor arguments :
120
121                 XY  => { config_class_name => ['SlaveY', foo => 'bar' ], },
122
123       class   Specify a Perl class to implement the above config class. This
124               Perl Class must inherit Config::Model::Node.
125

Forwarded methods

127       The following methods are forwarded to contained node:
128
129       fetch_element config_class_name get_element_name has_element
130       is_element_available element_type load fetch_element_value get_type
131       get_cargo_type describe
132

Methods

134   name
135       Return the name of the node (even if warped out).
136
137   is_accessible
138       Returns true if the node hidden behind this warped node is accessible,
139       i.e. the warp master have values so a node was warped in.
140
141   get_actual_node
142       Returns the node object hidden behind the warped node. Croaks if the
143       node is not accessible.
144
145   load_data
146       Parameters: "( hash_ref )"
147
148       Load configuration data with a hash ref. The hash ref key must match
149       the available elements of the node carried by the warped node.
150

EXAMPLE

152        $model ->create_config_class
153         (
154          element =>
155           [
156            tree_macro => { type => 'leaf',
157                            value_type => 'enum',
158                            choice     => [qw/XX XY XZ ZZ/]
159                          },
160            bar =>  {
161                      type => 'warped_node',
162                      follow => '! tree_macro',
163                      morph => 1,
164                      rules => [
165                                XX => { config_class_name
166                                          => [ 'ClassX', 'foo' ,'bar' ]}
167                                XY => { config_class_name => 'ClassY'},
168                                XZ => { config_class_name => 'ClassZ'}
169                               ]
170                    }
171           ]
172         );
173
174       In the example above we see that:
175
176       •   The 'bar' slot can refer to a "ClassX", "ClassZ" or "ClassY"
177           object.
178
179       •   The warper object is the "tree_macro" attribute of the root of the
180           object tree.
181
182       •   When "tree_macro" is set to "ZZ", "bar" is not available. Trying to
183           access "bar" raises an exception.
184
185       •   When "tree_macro" is changed from "ZZ" to "XX", "bar" refers to a
186           brand new "ClassX" object constructed with "ClassX->new(foo =>
187           'bar')"
188
189       •   Then, if "tree_macro" is changed from "XX" to "XY", "bar" refers to
190           a brand new "ClassY" object. But in this case, the object is
191           initialized with most if not all the attributes of "ClassX". This
192           copy is done whenever "tree_macro" is changed.
193

AUTHOR

195       Dominique Dumont, (ddumont at cpan dot org)
196

SEE ALSO

198       Config::Model::Instance, Config::Model, Config::Model::HashId,
199       Config::Model::ListId, Config::Model::AnyThing, Config::Model::Warper,
200       Config::Model::WarpedNode, Config::Model::Value
201

AUTHOR

203       Dominique Dumont
204
206       This software is Copyright (c) 2005-2022 by Dominique Dumont.
207
208       This is free software, licensed under:
209
210         The GNU Lesser General Public License, Version 2.1, February 1999
211
212
213
214perl v5.38.0                      2023-07-25    Config::Model::WarpedNode(3pm)
Impressum