X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet%2FPolyline.pm;h=e8e0ee0fe96e97c688e77a7d734c3305642583cf;hp=76656afc88c4c89ac4e0234f458b63b49f2f86b6;hb=7f9973057cc57660599aa4a093718cf343a48198;hpb=92147217516a40b35ca00c8e08939e8aa5478426 diff --git a/lib/LaTeX/TikZ/Set/Polyline.pm b/lib/LaTeX/TikZ/Set/Polyline.pm index 76656af..e8e0ee0 100644 --- a/lib/LaTeX/TikZ/Set/Polyline.pm +++ b/lib/LaTeX/TikZ/Set/Polyline.pm @@ -5,24 +5,31 @@ use warnings; =head1 NAME -LaTeX::TikZ::Set::Polyline - A set object representing a line. +LaTeX::TikZ::Set::Polyline - A set object representing a possibly closed path composed of contiguous lines. =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; use LaTeX::TikZ::Set::Point; +use LaTeX::TikZ::Interface; use LaTeX::TikZ::Functor; use Any::Moose; use Any::Moose 'Util::TypeConstraints'; -with 'LaTeX::TikZ::Set::Op'; +=head1 RELATIONSHIPS + +This class is a subclass of L, and as such inherits its C method. + +=cut + +extends 'LaTeX::TikZ::Set::Chain'; subtype 'LaTeX::TikZ::Set::Polyline::Vertices' => as 'ArrayRef[LaTeX::TikZ::Set::Point]' @@ -33,7 +40,15 @@ coerce 'LaTeX::TikZ::Set::Polyline::Vertices' => from 'ArrayRef[Any]' => via { [ map LaTeX::TikZ::Set::Point->new(point => $_), @$_ ] }; -has '_points' => ( +=head1 ATTRIBUTES + +=head2 C + +The list of L objects (or scalars that coerce into such objects) that make the successive vertices of the path. + +=cut + +has '+_kids' => ( is => 'ro', isa => 'LaTeX::TikZ::Set::Polyline::Vertices', init_arg => 'points', @@ -41,45 +56,39 @@ has '_points' => ( coerce => 1, ); -sub points { @{$_[0]->_points} } - -has 'closed' => ( - is => 'ro', - isa => 'Bool', - default => 0, -); - -sub path { - my $set = shift; +sub points { @{$_[0]->_kids} } - join ' -- ', map($_->path(@_), $set->points), - ($set->closed ? 'cycle' : ()); -} +around 'BUILDARGS' => sub { + my ($orig, $class, %args) = @_; -use LaTeX::TikZ::Interface polyline => sub { - shift; - - __PACKAGE__->new(points => \@_); + $class->$orig( + %args, + connector => '--', + ); }; -use LaTeX::TikZ::Interface closed_polyline => sub { - shift; +LaTeX::TikZ::Interface->register( + polyline => sub { + shift; - __PACKAGE__->new(points => \@_, closed => 1); -}; + __PACKAGE__->new(points => \@_); + }, + closed_polyline => sub { + shift; -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 => \@_, + cycle => 1 ); - } + }, ); __PACKAGE__->meta->make_immutable; +=head1 SEE ALSO + +L, L. + =head1 AUTHOR Vincent Pit, C<< >>, L.