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


NAME

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


SYNOPSIS

 $model ->create_config_class 
  (
   name => 'Class_with_one_changing_node',
   element =>
   [
    tree_macro => {type => 'leaf',
                   value_type => 'enum',
                   choice     => [qw/XY XZ mXY W/]
                  },
    'a_warped_node'
    => {
        type => 'warped_node',
        follow  => '! tree_macro',
        morph   => 1,
        rules => {
                  XY  => { config_class_name => ['SlaveY'], },
                  mXY => {
                          config_class_name   => 'SlaveY',
                          permission => 'intermediate'
                         },
                  XZ => { config_class_name => 'SlaveZ' }
                 }
       },
    'another_warped_node'
    => {
        type => 'warped_node',
        follow  => { tm => '! tree_macro'},
        morph   => 1,
        rules => [
                  '$tm eq "XY"'  => { config_class_name => ['SlaveY'], },
                  '$tm eq "mXY"' => {
                                    config_class_name   => 'SlaveY',
                                    permission => 'intermediate'
                                  },
                  '$tm eq "XZ"'  => { config_class_name => 'SlaveZ' }
                 ]
       },


DESCRIPTION

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 will specify one (or several) leaf in the configuration tree that will trigger the actual property change of the warped node. This leaf is also refered as warp master.

When the warp master(s) value(s) changes, WarpedNode will create 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:

 config_class_name
 permission
 level


Constructor

WarpedNode should not be created directly.


Warped node model declaration

Parameter overview

A warped node must be declared with the following parameters:

type

Always set to warped_node.

follow

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

morph

boolean. If 1, WarpedNode will try 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 will be assigned to object elements.

rules

Hash or array ref that specify the property change rules according to the warp master(s) value(s). See Warp rules argument in the Config::Model::WarpedThing manpage 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:

config_class_name

When requested by the warp master,the WarpedNode will create a new object of the type specified by this parameter:

  XZ => { config_class_name => 'SlaveZ' }

If you pass an array ref, the array will contain the class name and constructor arguments :

  XY  => { config_class_name => ['SlaveY', foo => 'bar' ], },
permission

Switch the permission of the slot when the object is warped in.


Forwarded methods

The following methods are forwared 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 config_model


Methods

name

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

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.

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.


EXAMPLE

 $model ->create_config_class 
  (
   permission => [ bar => 'advanced'] ,
   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:


AUTHOR

Dominique Dumont, (ddumont at cpan dot org)


SEE ALSO

the Config::Model::Instance manpage, the Config::Model manpage, the Config::Model::HashId manpage, the Config::Model::ListId manpage, the Config::Model::AnyThing manpage, the Config::Model::WarpedThing manpage, the Config::Model::WarpedNode manpage, the Config::Model::Value manpage

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