]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Polyline.pm
Reinstate the 'closed' parameter for Polyline
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Polyline.pm
index e1172eb36b0f25590138aca3e33d04fcaf0a679f..f982e91e661b63c0c5cab6e59aebe277ddd07b41 100644 (file)
@@ -9,27 +9,27 @@ LaTeX::TikZ::Set::Polyline - A set object representing a possibly closed path co
 
 =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';
+use Mouse;
+use Mouse::Util::TypeConstraints;
 
 =head1 RELATIONSHIPS
 
-This class consumes the L<LaTeX::TikZ::Set::Op> role, and as such implements the L</path> method.
+This class is a subclass of L<LaTeX::TikZ::Set::Chain>, and as such inherits its C<path> method.
 
 =cut
 
-with 'LaTeX::TikZ::Set::Op';
+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<points>
 
-The list of the successive vertices of the path.
+The list of L<LaTeX::TikZ::Set::Point> 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,58 +56,58 @@ has '_points' => (
  coerce   => 1,
 );
 
-sub points { @{$_[0]->_points} }
-
 =head2 C<closed>
 
-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
+sub points { @{$_[0]->_kids} }
 
-=head2 C<path>
+around 'BUILDARGS' => sub {
+ my ($orig, $class, %args) = @_;
 
-=cut
-
-sub path {
- my $set = shift;
+ delete $args{cycle};
 
- join ' -- ', map($_->path(@_), $set->points),
-              ($set->closed ? 'cycle' : ());
-}
+ $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<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Chain>.
+
 =head1 AUTHOR
 
 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.