X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FFunctor.pm;h=00c441a885d4a5cedcc6b3524205e7a69d29f5c8;hb=4822c0bbb4054d2e5068c0e9592c3965ee9d87f3;hp=efa66a095283d48de76a5c120eded45e40946d40;hpb=a44105abc490869376ff448faa654f429324abe2;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Functor.pm b/lib/LaTeX/TikZ/Functor.pm index efa66a0..00c441a 100644 --- a/lib/LaTeX/TikZ/Functor.pm +++ b/lib/LaTeX/TikZ/Functor.pm @@ -18,7 +18,32 @@ our $VERSION = '0.01'; =head1 DESCRIPTION A functor takes a L tree and clones it according to certain rules. -Rules can apply not only to L objects, but also to the L objects they contain. + +Rules can apply not only to L consumer objects, but also to the L consumer objects they contain. +The are stored as L objects. + +When the functor is called onto a set object, all its associated rules are tried successively, and the handler of the first matching rule is executed with : + +=over 4 + +=item * + +the functor object as its first argument ; + +=item * + +the current set object as its second argument ; + +=item * + +the arguments passed to the functor itself starting at the third argument. + +=back + +The handler is expected to return the new set/mod that will in the resulting set tree. +If the new set is different from the original, then the functor is applied to all the mods of the set, and their cloned version are added to the new set. + +If no matching rule is found, the object is returned as-is. =cut @@ -144,9 +169,10 @@ sub new { } } } - my $new_set = $rule ? $rule->handler->($self, $set, @_) - : $set; - my $is_new = $new_set ne $set; + return $set unless $rule; + + my $new_set = $rule->handler->($self, $set, @_); + return $set if $new_set == $set; my @new_mods; MOD: @@ -163,8 +189,7 @@ MOD: push @new_mods, $rule ? $rule->handler->($self, $mod, @_) : $mod; } - - $new_set->mod(@new_mods) if $is_new; + $new_set->mod(@new_mods); return $new_set; }, $class; @@ -209,7 +234,7 @@ sub default_rule { =head1 SEE ALSO -L. +L, L. =head1 AUTHOR