=head2 C<connector>
A code reference that describes how two successive elements of the chain are linked.
-It is called repeatedly with these arguments :
+When the L</path> method is , the connector is run repeatedly with these arguments :
=over 4
The C<$i+1>-th L<LaTeX::TikZ::Set> object in the chain.
+=item *
+
+The L<LaTeX::TikZ::Formatter> object.
+
=back
You can also pass a string, which will be upgraded to a code reference constantly returning that string ; or an array reference, which will be turned into a code reference returning the C<$i>-th element of the array when asked for the C<$i>-th link.
coerce => 1,
);
-has '_links' => (
- is => 'ro',
- isa => 'ArrayRef[Str]',
- init_arg => undef,
- default => sub { [ ] },
-);
-
=head1 METHODS
=head2 C<add>
my $set = shift;
$ltsp_tc->assert_valid($_) for @_;
- return $set unless @_;
- my $kids = $set->_kids;
- my $links = $set->_links;
- my $conn = $set->connector;
-
- push @$kids, shift @_ unless @$kids;
- return $set unless @_;
-
- my $prev = $kids->[-1];
- for my $i (0 .. $#_) {
- my $next = $_[$i];
- my $link = $set->$conn($#$kids, $prev, $next);
- confess('Invalid connector') unless defined $link and not blessed $link;
- push @$links, $link;
- push @$kids, $next;
- $prev = $next;
- }
+ push @{$set->_kids}, @_;
$set;
}
-sub BUILD {
- my ($set) = @_;
-
- my @kids = $set->kids;
- return unless @kids >= 2;
-
- my $links = $set->_links;
- my $conn = $set->connector;
-
- my $prev = $kids[0];
- for my $i (1 .. $#kids) {
- my $next = $_[$i];
- my $link = $set->$conn($i - 1, $prev, $next);
- confess('Invalid connector') unless defined $link and not blessed $link;
- push @$links, $link;
- $prev = $next;
- }
-}
-
=head2 C<path>
=cut
sub path {
- my $set = shift;
+ my ($set, $tikz) = @_;
my @kids = $set->kids;
return '' unless @kids;
- my $links = $set->_links;
my $conn = $set->connector;
- my $path = $kids[0]->path(@_);
+ my $prev = $kids[0];
+ my $path = $prev->path($tikz);
+
for my $i (1 .. $#kids) {
- my $link = ' ' . $links->[$i - 1] . ' ';
+ 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 . $kids[$i]->path(@_);
+ $path .= $link . $next->path($tikz);
+ $prev = $next;
}
return $path;
use strict;
use warnings;
-use Test::More tests => 28 + 2 * 21;
+use Test::More tests => 29 + 2 * 21;
use LaTeX::TikZ;
eval {
$join->add($bar);
};
+is $@, '',
+ 'adding too many sets to a chain set joined with an arrayref doesn\'t croak';
+
+eval {
+ using()->render($join);
+};
like $@, qr/^Invalid connector/,
'adding too many sets to a chain set joined with an arrayref croaks';