1Config::Model::Role::GrUasbe(r3)Contributed Perl DocumenCtoantfiiogn::Model::Role::Grab(3)
2
3
4
6 Config::Model::Role::Grab - Role to grab data from elsewhere in the
7 tree
8
10 version 2.133
11
13 $root->grab('foo:2 bar');
14 $root->grab(steps => 'foo:2 bar');
15 $root->grab(steps => 'foo:2 bar', type => 'leaf');
16 $root->grab_value(steps => 'foo:2 bar');
17
19 Role used to let a tree item (i.e. node, hash, list or leaf) to grab
20 another item or value from the configuration tree using a path (a bit
21 like an xpath path with a different syntax).
22
24 grab
25 Grab an object from the configuration tree.
26
27 Parameters are:
28
29 "steps" (or "step")
30 A string indicating the steps to follow in the tree to find the
31 required item. (mandatory)
32
33 "mode"
34 When set to "strict", "grab" throws an exception if no object is
35 found using the passed string. When set to "adaptative", the object
36 found last is returned. For instance, for the steps "good_step
37 wrong_step", only the object held by "good_step" is returned. When
38 set to "loose", grab returns undef in case of problem. (default is
39 "strict")
40
41 "type"
42 Either "node", "leaf", "hash" or "list" or an array ref containing
43 these values. Returns only an object of requested type. Depending
44 on "strict" value, "grab" either throws an exception or returns the
45 last object found with the requested type. (optional, default to
46 "undef", which means any type of object)
47
48 Examples:
49
50 $root->grab(steps => 'foo:2 bar', type => 'leaf')
51 $root->grab(steps => 'foo:2 bar', type => ['leaf','check_list'])
52
53 "autoadd"
54 When set to 1, "hash" or "list" configuration element are created
55 when requested by the passed steps. (default is 1).
56
57 grab_non_available
58 When set to 1, grab returns an object even if this one is not
59 available. I.e. even if this element was warped out. (default is
60 0).
61
62 The "steps" parameters is made of the following items separated by
63 spaces:
64
65 - Go up one node
66
67 ! Go to the root node.
68
69 !Foo Go up the configuration tree until the "Foo" configuration
70 class is found. Raise an exception if no "Foo" class is found
71 when root node is reached.
72
73 xxx Go down using "xxx" element.
74
75 xxx:yy Go down using "xxx" element and id "yy" (valid for hash or list
76 elements)
77
78 ?xxx Go up the tree until a node containing element "xxx" is found.
79 Then go down the tree like item "xxx".
80
81 "?xxx:yy" goes up the tree the same way. But no check is done
82 to see if id "yy" key actually exists or not. Only the element
83 "xxx" is considered when going up the tree.
84
85 grab_value
86 Like "grab", but returns the value of a leaf or check_list object, not
87 just the leaf object.
88
89 "grab_value" raises an exception if following the steps ends on
90 anything but a leaf or a check_list.
91
92 grab_annotation
93 Like "grab", but returns the annotation of an object.
94
95 grab_root
96 Returns the root of the configuration tree.
97
98 grab_ancestor
99 Parameter: a configuration class name
100
101 Go up the configuration tree until a node using the configuration class
102 is found. Returns the found node or undef.
103
104 Example:
105
106 # returns a Config::Model::Node object for a Systemd::Service config class
107 $self->grab('Systemd::Service');
108
110 Dominique Dumont
111
113 This software is Copyright (c) 2005-2018 by Dominique Dumont.
114
115 This is free software, licensed under:
116
117 The GNU Lesser General Public License, Version 2.1, February 1999
118
119
120
121perl v5.28.1 2019-02-02 Config::Model::Role::Grab(3)