X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet%2FPolyline.pm;h=f982e91e661b63c0c5cab6e59aebe277ddd07b41;hb=134d77c279c20662ad5a3e8904e71572def1478e;hp=987c321d380f3cb7efce1437b8d68f29a09cc2ef;hpb=6832c809e7591e1c3e2809654f814c298d28d2ef;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Set/Polyline.pm b/lib/LaTeX/TikZ/Set/Polyline.pm index 987c321..f982e91 100644 --- a/lib/LaTeX/TikZ/Set/Polyline.pm +++ b/lib/LaTeX/TikZ/Set/Polyline.pm @@ -20,16 +20,16 @@ use LaTeX::TikZ::Set::Point; use LaTeX::TikZ::Interface; use LaTeX::TikZ::Functor; -use Any::Moose; -use Any::Moose 'Util::TypeConstraints'; +use Mouse; +use Mouse::Util::TypeConstraints; =head1 RELATIONSHIPS -This class consumes the L role, and as such implements the L method. +This class is a subclass of L, and as such inherits its C method. =cut -with 'LaTeX::TikZ::Set::Path'; +extends 'LaTeX::TikZ::Set::Chain'; subtype 'LaTeX::TikZ::Set::Polyline::Vertices' => as 'ArrayRef[LaTeX::TikZ::Set::Point]' @@ -44,11 +44,11 @@ coerce 'LaTeX::TikZ::Set::Polyline::Vertices' =head2 C -The list of the successive vertices of the path. +The list of L objects (or scalars that coerce into such objects) that make the successive vertices of the path. =cut -has '_points' => ( +has '+_kids' => ( is => 'ro', isa => 'LaTeX::TikZ::Set::Polyline::Vertices', init_arg => 'points', @@ -56,87 +56,57 @@ has '_points' => ( coerce => 1, ); -sub points { @{$_[0]->_points} } - =head2 C -A boolean that indicates whether the path is closed or not. +A boolean that indicates whether the polyline is closed or not. =cut has 'closed' => ( - is => 'ro', - isa => 'Bool', - default => 0, + is => 'ro', + isa => 'Bool', + required => 1, + default => 0, ); -=head1 METHODS - -=head2 C - -=cut - -sub path { - my $set = shift; - - join ' -- ', map($_->path(@_), $set->points), - ($set->closed ? 'cycle' : ()); -} - -=head2 C - -=cut - -sub begin { - my $set = shift; - - my @points = $set->points; - return undef unless @points; - - $points[0]->begin; -} - -=head2 C - -=cut +sub points { @{$_[0]->_kids} } -sub end { - my $set = shift; +around 'BUILDARGS' => sub { + my ($orig, $class, %args) = @_; - my @points = $set->points; - return undef unless @points; + delete $args{cycle}; - $points[-1]->end; -} + $class->$orig( + %args, + connector => '--', + cycle => $args{closed}, + ); +}; LaTeX::TikZ::Interface->register( polyline => sub { shift; - __PACKAGE__->new(points => \@_); + __PACKAGE__->new( + points => \@_, + closed => 0, + ); }, closed_polyline => sub { shift; - __PACKAGE__->new(points => \@_, closed => 1); - }, -); - -LaTeX::TikZ::Functor->default_rule( - (__PACKAGE__) => sub { - my ($functor, $set, @args) = @_; - $set->new( - points => [ map $_->$functor(@args), $set->points ], - closed => $set->closed, + __PACKAGE__->new( + points => \@_, + closed => 1, ); - } + }, ); __PACKAGE__->meta->make_immutable; =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR