]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Polyline.pm
Reimplement LT::Set::Polyline as a child class of LT::Set::Chain
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Polyline.pm
1 package LaTeX::TikZ::Set::Polyline;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ::Set::Polyline - A set object representing a possibly closed path composed of contiguous lines.
9
10 =head1 VERSION
11
12 Version 0.02
13
14 =cut
15
16 our $VERSION = '0.02';
17
18 use LaTeX::TikZ::Set::Point;
19
20 use LaTeX::TikZ::Interface;
21 use LaTeX::TikZ::Functor;
22
23 use Any::Moose;
24 use Any::Moose 'Util::TypeConstraints';
25
26 =head1 RELATIONSHIPS
27
28 This class is a subclass of L<LaTeX::TikZ::Set::Chain>, and as such inherits its C<path> method.
29
30 =cut
31
32 extends 'LaTeX::TikZ::Set::Chain';
33
34 subtype 'LaTeX::TikZ::Set::Polyline::Vertices'
35      => as 'ArrayRef[LaTeX::TikZ::Set::Point]'
36      => where { @$_ >= 2 }
37      => message { 'at least two LaTeX::TikZ::Set::Point objects are needed in order to build a polyline' };
38
39 coerce 'LaTeX::TikZ::Set::Polyline::Vertices'
40     => from 'ArrayRef[Any]'
41     => via { [ map LaTeX::TikZ::Set::Point->new(point => $_), @$_ ] };
42
43 =head1 ATTRIBUTES
44
45 =head2 C<points>
46
47 The list of L<LaTeX::TikZ::Set::Point> objects (or scalars that coerce into such objects) that make the successive vertices of the path.
48
49 =cut
50
51 has '+_kids' => (
52  is       => 'ro',
53  isa      => 'LaTeX::TikZ::Set::Polyline::Vertices',
54  init_arg => 'points',
55  required => 1,
56  coerce   => 1,
57 );
58
59 sub points { @{$_[0]->_kids} }
60
61 around 'BUILDARGS' => sub {
62  my ($orig, $class, %args) = @_;
63
64  $class->$orig(
65   %args,
66   connector => '--',
67  );
68 };
69
70 LaTeX::TikZ::Interface->register(
71  polyline => sub {
72   shift;
73
74   __PACKAGE__->new(points => \@_);
75  },
76  closed_polyline => sub {
77   shift;
78
79   __PACKAGE__->new(
80    points => \@_,
81    cycle  => 1
82   );
83  },
84 );
85
86 __PACKAGE__->meta->make_immutable;
87
88 =head1 SEE ALSO
89
90 L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Chain>.
91
92 =head1 AUTHOR
93
94 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
95
96 You can contact me by mail or on C<irc.perl.org> (vincent).
97
98 =head1 BUGS
99
100 Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
101 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
102
103 =head1 SUPPORT
104
105 You can find documentation for this module with the perldoc command.
106
107     perldoc LaTeX::TikZ
108
109 =head1 COPYRIGHT & LICENSE
110
111 Copyright 2010 Vincent Pit, all rights reserved.
112
113 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
114
115 =cut
116
117 1; # End of LaTeX::TikZ::Set::Polyline