Config...e::Grab(3pm)
π Config::Model::Role::Grab β the whole vibe π
okay bestie, so this is a role (yes, a Perl role, we love a shared-behaviour moment) and it lives in the Config::Model universe. It's the one that lets any tree item β node, hash, list, or leaf β reach out and grab another item or value from the configuration tree by following a path. And no, it's not xpath, but it's giving xpath's cooler cousin with a different syntax. iykyk β¨
It's documented under the User Contributed Perl Documentation umbrella, so you know it's the people's manpage fr fr. π«Ά
β¨ VERSION β¨
version 2.166 β the current era of this icon. π
πΈ SYNOPSIS πΈ
here's the snack preview, exactly as it goes down:
$root->grab('foo:2 bar');
$root->grab(steps => 'foo:2 bar');
$root->grab(steps => 'foo:2 bar', type => 'leaf');
$root->grab_value(steps => 'foo:2 bar');
$root->grab_value(steps => '"a.string"'); # contains . in name -> quote
see that last one? if your name has a . in it, you quote it, no negotiation. π
π¦ DESCRIPTION π¦
So the whole point: this role lets a tree item (i.e. a node, hash, list or leaf) grab another item or value out of the configuration tree using a path β kinda like an xpath path, but with a different syntax. that's it, that's the premise, and it's lowkey iconic. π
π METHODS π
π grab
Grab an object from the configuration tree. main character method, honestly.
Parameters are:
steps(orstep) β a string indicating the steps to follow in the tree to find the required item. (mandatory β you cannot skip this one bestie, it's not optional and it's not cute to try)modeβ controls the drama level when things go wrong. When set tostrict,grabthrows an exception if no object is found using the passed string. When set toadaptative, the object found last is returned β for instance, for the stepsgood_step wrong_step, only the object held bygood_stepcomes back. When set toloose,grabreturnsundefin case of problem. (default isstrictβ yes, it's strict by default, it said what it said π)typeβ eithernode,leaf,hashorlist, or an array ref containing these values. Returns only an object of the requested type. Depending on thestrictvalue,grabeither throws an exception or returns the last object found with the requested type. (optional, default isundef, which means any type of object β free spirit behaviour β¨)
Examples:
$root->grab(steps => 'foo:2 bar', type => 'leaf')
$root->grab(steps => 'foo:2 bar', type => ['leaf','check_list'])
autoaddβ when set to 1,hashorlistconfiguration elements are created when requested by the passed steps. (default is 1 β it's helpful like that π«Ά)grab_non_availableβ when set to 1,grabreturns an object even if this one is not available. I.e. even if this element was warped out. (default is 0)
Now, the steps parameter is made of the following items, separated by spaces:
-β Go up one node!β Go to the root node.!Fooβ Go up the configuration tree until theFooconfiguration class is found. Raise an exception if noFooclass is found when root node is reached. π (like, it will yell.)xxxβ Go down usingxxxelement. Quotes must be used if the element name is not alphanumeric.xxx:yyβ Go down usingxxxelement and idyy(valid for hash or list elements). Quotes must be used if the id is not alphanumeric.?xxxβ Go up the tree until a node containing elementxxxis found. Then go down the tree like itemxxx.?xxx:yygoes up the tree the same way. But no check is done to see if idyykey actually exists or not. Only the elementxxxis considered when going up the tree. (so, uh, be aware of that β¨)
π grab_value
Like grab, but returns the value of a leaf or check_list object, not just the leaf object. giving actual-data energy π
grab_value raises an exception if following the steps ends on anything but a leaf or a check_list. no cap.
π grab_annotation
Like grab, but returns the annotation of an object. π
π grab_root
Returns the root of the configuration tree. short, sweet, iconic.
π grab_ancestor
Parameter: a configuration class name.
Go up the configuration tree until a node using the configuration class is found. Returns the found node or undef.
Example:
# returns a Config::Model::Node object for a Systemd::Service config class
$self->grab('Systemd::Service');
π AUTHOR π
Dominique Dumont β the legend behind this whole thing. π«Ά
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2005-2022 by Dominique Dumont.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999
okay so fr fr, remember: this is theConfig...e::Grab(3pm)page, part of theUser Contributed Perl Documentation, built for perl v5.42.3 and dated 2026-07-23. that's the whole tea. go grab something (respectfully). πβ¨π¦πΈπ π«Ά
π¦ where this page comes from
- ubuntu stonking: libconfig-model-perl 2.166-1 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms