From: Vincent Pit Date: Wed, 22 Apr 2015 19:44:41 +0000 (-0300) Subject: Also define a default functor rule for the new Polyline X-Git-Tag: v0.03~6 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=93edf9c5c04a04fbd3c8dbf04eacaf66736ff6ee;p=perl%2Fmodules%2FLaTeX-TikZ.git Also define a default functor rule for the new Polyline Otherwise the Chain default rule is used instead, but it does not know how to create a Polyline. --- diff --git a/lib/LaTeX/TikZ/Set/Polyline.pm b/lib/LaTeX/TikZ/Set/Polyline.pm index f982e91..627fd81 100644 --- a/lib/LaTeX/TikZ/Set/Polyline.pm +++ b/lib/LaTeX/TikZ/Set/Polyline.pm @@ -102,6 +102,16 @@ LaTeX::TikZ::Interface->register( }, ); +LaTeX::TikZ::Functor->default_rule( + (__PACKAGE__) => sub { + my ($functor, $set, @args) = @_; + $set->new( + points => [ map $_->$functor(@args), $set->kids ], + closed => $set->closed, + ); + } +); + __PACKAGE__->meta->make_immutable; =head1 SEE ALSO diff --git a/t/30-functor.t b/t/30-functor.t index e455a9d..74ff18d 100644 --- a/t/30-functor.t +++ b/t/30-functor.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 10 + 2 * 7; +use Test::More tests => 11 + 2 * 8; use LaTeX::TikZ; @@ -78,6 +78,19 @@ check $seq2, 'the translated sequence', <<'RES'; \end{scope} RES +my $poly = Tikz->closed_polyline( + [ 0, 0 ], [ 1, 0 ], [ 1, 1 ], [ 0, 1 ] +); + +my $poly2 = eval { + $poly->$translate(Tikz->point(-1, 1)); +}; +is $@, '', 'translating a polyline doesn\'t croak'; + +check $poly2, 'the translated polyline', <<'RES'; +\draw (-1cm,1cm) -- (0cm,1cm) -- (0cm,2cm) -- (-1cm,2cm) -- cycle ; +RES + my $strip = eval { Tikz->functor( '+LaTeX::TikZ::Mod' => sub { return },