]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Chain.pm
This is 0.03
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Chain.pm
index 2c640c2821495cddc51ab9cb7a3e3db69bb21035..308de760eaf17c35259b640e3454c13e08c9f0b5 100644 (file)
@@ -9,21 +9,22 @@ LaTeX::TikZ::Set::Chain - A set object representing a connected path between sev
 
 =head1 VERSION
 
-Version 0.02
+Version 0.03
 
 =cut
 
-our $VERSION = '0.02';
+our $VERSION = '0.03';
 
 use LaTeX::TikZ::Set::Point;
+use LaTeX::TikZ::Set::Raw;
 
 use LaTeX::TikZ::Interface;
 use LaTeX::TikZ::Functor;
 
 use LaTeX::TikZ::Tools;
 
-use Any::Moose;
-use Any::Moose 'Util::TypeConstraints' => [ qw<subtype as coerce from via> ];
+use Mouse;
+use Mouse::Util::TypeConstraints qw<subtype as coerce from via>;
 
 =head1 RELATIONSHIPS
 
@@ -68,7 +69,7 @@ sub kids { @{$_[0]->_kids} }
 =head2 C<connector>
 
 A code reference that describes how two successive elements of the chain are linked.
-When the L</path> method is , the connector is run repeatedly with these arguments :
+When the L</path> method is called, the connector is run repeatedly with these arguments :
 
 =over 4
 
@@ -116,6 +117,18 @@ has 'connector' => (
  coerce   => 1,
 );
 
+=head2 C<cycle>
+
+A boolean that indicates whether the path is a cycle or not.
+
+=cut
+
+has 'cycle' => (
+ is      => 'ro',
+ isa     => 'Bool',
+ default => 0,
+);
+
 =head1 METHODS
 
 =head2 C<add>
@@ -139,7 +152,7 @@ sub add {
 =cut
 
 sub path {
- my ($set, $tikz) = @_;
+ my $set = shift;
 
  my @kids  = $set->kids;
  return '' unless @kids;
@@ -147,15 +160,22 @@ sub path {
  my $conn  = $set->connector;
 
  my $prev  = $kids[0];
- my $path  = $prev->path($tikz);
+ my $path  = $prev->path(@_);
+
+ if ($set->cycle) {
+  push @kids, LaTeX::TikZ::Set::Raw->new(
+   content => 'cycle',
+  );
+ }
 
+ my $tikz = $_[0];
  for my $i (1 .. $#kids) {
   my $next = $kids[$i];
   my $link = $set->$conn($i - 1, $prev, $next, $tikz);
   confess('Invalid connector') unless defined $link and not blessed $link;
   $link    = " $link ";
   $link    =~ s/\s+/ /g;
-  $path   .= $link . $next->path($tikz);
+  $path   .= $link . $next->path(@_);
   $prev    = $next;
  }
 
@@ -223,6 +243,7 @@ LaTeX::TikZ::Functor->default_rule(
   $set->new(
    kids      => [ map $_->$functor(@args), $set->kids ],
    connector => $set->connector,
+   cycle     => $set->cycle,
   );
  }
 );
@@ -252,7 +273,7 @@ You can find documentation for this module with the perldoc command.
 
 =head1 COPYRIGHT & LICENSE
 
-Copyright 2011 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.