]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Polyline.pm
This is 0.03
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Polyline.pm
index 76656afc88c4c89ac4e0234f458b63b49f2f86b6..0c19f431263eb6955958afb51173067adfe38ce8 100644 (file)
@@ -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.03
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.03';
 
 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;
 
-with 'LaTeX::TikZ::Set::Op';
+=head1 RELATIONSHIPS
+
+This class is a subclass of L<LaTeX::TikZ::Set::Chain>, and as such inherits its C<path> 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<points>
+
+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 '+_kids' => (
  is       => 'ro',
  isa      => 'LaTeX::TikZ::Set::Polyline::Vertices',
  init_arg => 'points',
@@ -41,38 +56,57 @@ has '_points' => (
  coerce   => 1,
 );
 
-sub points { @{$_[0]->_points} }
+=head2 C<closed>
+
+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,
 );
 
-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;
+ delete $args{cycle};
 
- __PACKAGE__->new(points => \@_);
+ $class->$orig(
+  %args,
+  connector => '--',
+  cycle     => $args{closed},
+ );
 };
 
-use LaTeX::TikZ::Interface closed_polyline => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ polyline => sub {
+  shift;
 
- __PACKAGE__->new(points => \@_, closed => 1);
-};
+  __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 ],
+   points => [ map $_->$functor(@args), $set->kids ],
    closed => $set->closed,
   );
  }
@@ -80,6 +114,10 @@ LaTeX::TikZ::Functor->default_rule(
 
 __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>.
@@ -99,7 +137,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2010 Vincent Pit, all rights reserved.
+Copyright 2010,2011,2012,2013,2014,2015 Vincent Pit, all rights reserved.
 
 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.