Config...pedNode(3pm)
π Config::Model::WarpedNode β the manual, but make it make sense π
okay bestie, gather round, because this one is literally the shape-shifter of the Config::Model universe and I am obsessed. This page lives in the 3pm section of the perl man pages (User Contributed Perl Documentation), and we're gonna get you fluent in it. No cap. π¦
β¨ NAME β¨
Config::Model::WarpedNode β a Node that changes config class properties. it's giving glow-up on demand. π
πΈ VERSION πΈ
version 2.166 β that's the one we're talking about, periodt.
π SYNOPSIS π
here's the whole vibe in code, look at it, it's iconic:
use Config::Model;
my $model = Config::Model->new;
foreach (qw/X Y/) {
$model->create_config_class(
name => "Class$_",
element => [ foo => {qw/type leaf value_type string/} ]
);
}
$model->create_config_class(
name => "MyClass",
element => [
master_switch => {
type => 'leaf',
value_type => 'enum',
choice => [qw/cX cY/]
},
'a_warped_node' => {
type => 'warped_node',
warp => {
follow => { ms => '! master_switch' },
rules => [
'$ms eq "cX"' => { config_class_name => 'ClassX' },
'$ms eq "cY"' => { config_class_name => 'ClassY' },
]
}
},
],
);
my $inst = $model->instance(root_class_name => 'MyClass' );
my $root = $inst->config_root ;
print "Visible elements: ",join(' ',$root->get_element_name),"\n" ;
# Visible elements: master_switch
$root->load( steps => 'master_switch=cX' );
print "Visible elements: ",join(' ',$root->get_element_name),"\n" ;
# Visible elements: master_switch a_warped_node
my $node = $root->grab('a_warped_node') ;
print "a_warped_node class: ",$node->config_class_name,"\n" ;
# a_warped_node class: ClassX
$root->load( steps => 'master_switch=cY' );
print "a_warped_node class: ",$node->config_class_name,"\n" ;
# a_warped_node class: ClassY
like, the node becomes a whole different class depending on a switch. main character energy fr fr. π
π DESCRIPTION π
okay so here's the tea. This class provides a way to change dynamically the configuration class (or some other properties) of a node. and the changes happen according to the model declaration β not vibes, actual declarations. π§
This declaration specifies one (or several) leaf in the configuration tree that triggers the actual property change of the warped node. that leaf gets called the warp master. iykyk.
When the warp master(s) value(s) changes, WarpedNode creates an instance of the new class required by the warp master. it's a whole transformation sequence. β¨
If the morph parameter is set, the values held by the old object are (if possible) copied to the new instance of the object using copy_from method. if possible β that's the catch, bestie.
Warped node can alter the following properties:
config_class_name
level
π«Ά Constructor π«Ά
girl, do not call this yourself: WarpedNode should not be created directly. π
π Warped node model declaration π
π« Parameter overview π«
a warped node must be declared with the following parameters, no skipping:
typeβ Always set towarped_node. that's the whole personality.followβ a grab string leading to theConfig::Model::Valuewarp master. See "Warp follow argument" in Config::Model::Warper for details. (go read that, seriously.)morphβ boolean. If1,WarpedNodetries to recursively copy the value from the old object to the new object usingcopy_frommethod. When a copy is not possible,undefvalues are assigned to object elements. so sometimes you just getundefand that's the deal, sorry babe. πrulesβ a Hash or array ref that specify the property change rules according to the warp master(s) value(s). See "Warp rules argument" in Config::Model::Warper for details on how to specify the warp master values (or combination of values). the rules are the lore. π
β Effect declaration β
for a warped node, the effects are declared with these parameters:
config_class_nameβ when requested by the warp master, theWarpedNodecreates a new object of the type specified by this parameter:
XZ => { config_class_name => 'SlaveZ' }
Instead of a string, you can an array ref which contains the class name and constructor arguments:
XY => { config_class_name => ['SlaveY', foo => 'bar' ], },
classβ specify a Perl class to implement the above config class. This Perl Class must inheritConfig::Model::Node. yes, must. required. don't fight it. π
π¦ Forwarded methods π¦
The following methods are forwarded to contained node β so you can call them and they just get handed off, like passing the aux:
fetch_element config_class_name get_element_name has_element
is_element_available element_type load fetch_element_value get_type
get_cargo_type describe
π Methods π
nameβ Return the name of the node (even if warped out). iconic behaviour honestly.is_accessibleβ Returns true if the node hidden behind this warped node is accessible, i.e. the warp master have values so a node was warped in. π«get_actual_nodeβ Returns the node object hidden behind the warped node. Croaks if the node is not accessible. so like, don't call it when it's not there, bestie. πload_dataβ Parameters:( hash_ref )
Load configuration data with a hash ref. The hash ref key must match the available elements of the node carried by the warped node. match the keys, that's the rule. π
π₯ EXAMPLE π₯
look at this whole thing:
$model ->create_config_class
(
element =>
[
tree_macro => {
type => 'leaf',
value_type => 'enum',
choice => [qw/XX XY XZ ZZ/]
},
bar => {
'type' => 'warped_node'
'morph' => 1,
'follow' => {
'f1' => '! tree_macro'
},
'rules' => [
{
'when' => '$f1 eq \'XX\'',
'apply' => {'config_class_name' => ['ClassX', 'foo', 'bar']}
},
{
'when' => '$f1 eq \'XY\''
'apply' => {'config_class_name' => 'ClassY'},
},
{
'when' => '$f1 eq \'XZ\''
'apply' => {'config_class_name' => 'ClassZ'},
}
],
}
]
);
In the example above we see that:
- The 'bar' slot can refer to a
ClassX,ClassZorClassYobject. π - The warper object is the
tree_macroattribute of the root of the object tree. - When
tree_macrois set toZZ,baris not available. Trying to accessbarraises an exception. π¨ so like, no touching. - When
tree_macrois changed fromZZtoXX,barrefers to a brand newClassXobject constructed withClassX->new(foo => 'bar'). fresh out the box. β¨ - Then, if
tree_macrois changed fromXXtoXY,barrefers to a brand newClassYobject. But in this case, the object is initialized with most if not all the attributes ofClassX. This copy is done whenevertree_macrois changed. that's the morph doing its thing. πͺ
π AUTHOR π
Dominique Dumont, (ddumont at cpan dot org)
πΈ SEE ALSO πΈ
Config::Model::Instance, Config::Model, Config::Model::HashId, Config::Model::ListId, Config::Model::AnyThing, Config::Model::Warper, Config::Model::WarpedNode, Config::Model::Value
π AUTHOR π
Dominique Dumont
π 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
k that's the whole manual, you ate it, bestie. this page is from perl v5.42.3, dated 2026-07-23, and it's part of Config::Model::WarpedNode in the 3pm docs. go forth and warp responsibly. π
π¦β¨
π¦ 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