Dominique Dumont > Config-Model > Config::Model::WarpedNode



Annotate this POD


View/Report Bugs
Module Version: 2.092   Source  


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


version 2.092


 use Config::Model;

 my $model = Config::Model->new;
 foreach (qw/X Y/) {
        name    => "Class$_",
        element => [ foo => {qw/type leaf value_type string/} ]
    name => "MyClass",

    element => [
        master_switch => {
            type       => 'leaf',
            value_type => 'enum',
            choice     => [qw/cX cY/]

        'a_warped_node' => {
            type   => 'warped_node',
            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


This class provides a way to change dynamically the configuration class (or some other properties) of a node. The changes are done according to the model declaration.

This declaration specifies one (or several) leaf in the configuration tree that triggers the actual property change of the warped node. This leaf is also referred as warp master.

When the warp master(s) value(s) changes, WarpedNode creates an instance of the new class required by the warp master.

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.

Warped node can alter the following properties:


Constructor ^

WarpedNode should not be created directly.

Warped node model declaration ^

Parameter overview

A warped node must be declared with the following parameters:


Always set to warped_node.


Grab string leading to the Config::Model::Value warp master. See "Warp follow argument" in Config::Model::Warper for details.


boolean. If 1, WarpedNode tries to recursively copy the value from the old object to the new object using copy_from method. When a copy is not possible, undef values are assigned to object elements.


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).

Effect declaration

For a warped node, the effects are declared with these parameters:


When requested by the warp master,the WarpedNode creates 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' ], },

Specify a Perl class to implement the above config class. This Perl Class must inherit Config::Model::Node.

Forwarded methods ^

The following methods are forwarded to contained node:

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 ^


Return the name of the node (even if warped out).


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.


Returns the node object hidden behind the warped node. Croaks if the node is not accessible.

load_data ( 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.


 $model ->create_config_class 
   element =>
     tree_macro => { type => 'leaf',
                     value_type => 'enum',
                     choice     => [qw/XX XY XZ ZZ/]
     bar =>  {
               type => 'warped_node',
               follow => '! tree_macro', 
               morph => 1,
               rules => [
                         XX => { config_class_name 
                                   => [ 'ClassX', 'foo' ,'bar' ]}
                         XY => { config_class_name => 'ClassY'},
                         XZ => { config_class_name => 'ClassZ'}

In the example above we see that:


Dominique Dumont, (ddumont at cpan dot org)


Config::Model::Instance, Config::Model, Config::Model::HashId, Config::Model::ListId, Config::Model::AnyThing, Config::Model::Warper, Config::Model::WarpedNode, Config::Model::Value


Dominique Dumont


This software is Copyright (c) 2005-2016 by Dominique Dumont.

This is free software, licensed under:

  The GNU Lesser General Public License, Version 2.1, February 1999
syntax highlighting: