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


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 the Config::Model::Value manpage. This class provides a set of methods that are expected by a warp master from a warped class.

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

WarpThing does not provide a constructor.


Warper and warped

Warping an object means that 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 masters.


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' ]

You can also use named parameters:

 follow => { m1 => '! macro1', m2 => '- macro2' }

Warp rules argument

String, hash ref or array ref that specify the warped object property changes. These rules specifies the actual property changes for the warped object depending on the value(s) of the warp master(s).

E.g. for a simple case (rules is a hash ref) :

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

In case of similar effects, you can use named parameters and a boolean expression to specify the effect. The first match will be applied. In this case, rules is a list ref:

  follow => { m => '! macro1' } ,
  rules => [ '$m eq "A"'               => { <effect for macro1 == A> },
             '$m eq "B" or $m eq"C "'  => { <effect for macro1 == B|C > }
           ]

In case of several warp masters, follow must use named parameters, and rules must use boolean expression:

 follow => { m1 => '! macro1', m2 => '- macro2' } ,
 rules => [
           '$m1 eq "A" && $m2 eq "C"' => { <effect for A C> },
           '$m1 eq "A" && $m2 eq "D"' => { <effect for A D> },
           '$m1 eq "B" && $m2 eq "C"' => { <effect for B C> },
           '$m1 eq "B" && $m2 eq "D"' => { <effect for B D> },
          ]

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

 follow => { m1 => '! macro1', m2 => '- macro2' } ,
 rules => [
           '$m1 eq "A" && $m2 eq "C"' => { <effect X> },
           '$m1 eq "A" && $m2 eq "D"' => { <effect Y> },
           '$m1 eq "B" && $m2 eq "C"' => { <effect Y> },
           '$m1 eq "B" && $m2 eq "D"' => { <effect Y> },
          ]

In this case, you can use different boolean expression to save typing:

 follow => { m1 => '! macro1', m2 => '- macro2' } ,
 rules => [
           '$m1 eq "A" && $m2 eq "C"' => { <effect X> },
           '$m1 eq "A" && $m2 eq "D"' => { <effect Y> },
           '$m1 eq "B" && ( $m2 eq "C" or $m2 eq "D") ' => { <effect Y> },
          ]

Note that the boolean expression will be sanitised and used in a Perl eval, so you can use most Perl syntax and regular expressions.


Methods

warp_error()

This method returns a string describing:


How does this work ?

Registration
Master update


AUTHOR

Dominique Dumont, (ddumont at cpan dot org)


SEE ALSO

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

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