The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Config::Model::WarpedThing - Base class for warped classes

SYNOPSIS

 use base qw/Config::Model::WarpedThing/ ;

DESCRIPTION

This class must be inherited by all classes that can be warped by Config::Model::Value. This class provides a set of methods that are expected by a warp master from a warped class.

Currently this class is inherited by Config::Model::Value, Config::Model::AnyId and Config::Model::WarpedNode.

WarpThing does not provide a constructor.

Warper and warped

Warping an object means the the properties of the object will be changed depending on the value of another object.

The changed object is refered as the warped object.

The other object that holds the important value is referred as the warp master or the warper object.

You can also set up several warp master for one warped object. This means that the properties of the warped object will be changed according to a combination of values of the warp master.

How does this work ?

Registration
  • When a warped object is created, the constructor will register to the warp masters. The warp master are found by using the special string passed to the follow parameter. As explained in grab method, the string provides the location of the warp master in the configuration tree using a symbolic form.

  • Then the warped object retrieve the value(s) of the warp master(s)

  • Then the warped object warps itself using the above value(s). Depending on these value(s), the properties of the warped object will be modified.

Master update
  • When a warp master value is updated, the warp master will call all its warped object and pass them the new master value.

  • Then each warped object will modify its properties according to the new warp master value.

Warp arguments

Warp arguments are passed in a hash ref whose keys are follow and and rules:

Warp follow argument

Grab string leading to the Config::Model::Value warp master. E.g.:

 follow => '! tree_macro' 

In case of several warp master, follow will be set to an array ref of several grab string:

 follow => [ '! macro1', '- macro2' ]

Warp rules argument

Hash or array ref that specify the warped object property changes. These rules specfies the actual property changes for the warped object depending on the value(s) of the warp master(s). E.g.:

 follow => [ '! macro1' ],
 rules => { A => { <effect for macro1 == A> },
            B => { <effect for macro1 == B> }
          }

In case of similar effects, you can group the rules:

  follow => [ '! macro1' ],
  rules => [ A => { <effect for macro1 == A> },
             ['B','C'] => { <effect for macro1 == B|C > }
           ]

In case of several warp masters, the rules must be an array ref:

 follow => [ '! macro1', '- macro2' ],
 rules => [
           [qw/A C/] => {<effect for macro1 == A and macro2 == C>},
           [qw/A D/] => {<effect for macro1 == A and macro2 == D>},
           [qw/B C/] => {<effect for macro1 == B and macro2 == C>},
           [qw/B D/] => {<effect for macro1 == B and macro2 == D>},
          ]

The rules array structure is the same as the previous example, but the interpretation is different because follow points to more that one item.

Of course some combinations of warp master values can have the same effect:

 follow => [ '! macro1', '- macro2' ],
 rules => [
           [qw/A C/] => {<effect X>},
           [qw/A D/] => {<effect Y>},
           [qw/B C/] => {<effect Y>},
           [qw/B D/] => {<effect Y>},
          ]

In this case, you can use this notation to save typing:

 follow => [ '! macro1', '- macro2' ],
 rules => [
           [ 'A',  'C'      ] => {<effect X>},
           [ 'A',  'D'      ] => {<effect Y>},
           [ 'B', ['C','D'] ] => {<effect Y>},
          ]

Methods

warp_error()

This method returns a string describing:

  • The location(s) of the warp master

  • The current value(s) of the warp master(s)

  • The other values accepted by the warp master that can be tried (if the warp master is an enumerated type)

AUTHOR

Dominique Dumont, (ddumont at cpan dot org)

SEE ALSO

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