]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Union.pm
Just use Mouse instead of Any::Moose
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Union.pm
1 package LaTeX::TikZ::Set::Union;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ::Set::Union - A set object representing a path formed by the reunion of several subpaths.
9
10 =head1 VERSION
11
12 Version 0.02
13
14 =cut
15
16 our $VERSION = '0.02';
17
18 use LaTeX::TikZ::Interface;
19 use LaTeX::TikZ::Functor;
20
21 use LaTeX::TikZ::Tools;
22
23 use Mouse;
24
25 =head1 RELATIONSHIPS
26
27 This class consumes the L<LaTeX::TikZ::Set::Path> and L<LaTeX::TikZ::Set::Container> roles, and as such implements the L</path>, L</kids> and L</add> methods.
28
29 =cut
30
31 with qw<
32  LaTeX::TikZ::Set::Path
33  LaTeX::TikZ::Set::Container
34 >;
35
36 =head1 ATTRIBUTES
37
38 =head2 C<kids>
39
40 The L<LaTeX::TikZ::Set::Path> objects that form the path.
41
42 =cut
43
44 has '_kids' => (
45  is       => 'ro',
46  isa      => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Path]]',
47  init_arg => 'kids',
48  default  => sub { [ ] },
49 );
50
51 sub kids { @{$_[0]->_kids} }
52
53 =head1 METHODS
54
55 =head2 C<add>
56
57 =cut
58
59 my $ltsp_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Set::Path');
60
61 sub add {
62  my $set = shift;
63
64  $ltsp_tc->assert_valid($_) for @_;
65
66  push @{$set->_kids}, @_;
67
68  $set;
69 }
70
71 =head2 C<path>
72
73 =cut
74
75 sub path {
76  my $set = shift;
77
78  join ' ', map $_->path(@_), $set->kids;
79 }
80
81 =head2 C<begin>
82
83 =cut
84
85 sub begin {
86  my $set = shift;
87
88  my @kids = $set->kids;
89  return undef unless @kids;
90
91  $kids[0]->begin;
92 }
93
94 =head2 C<end>
95
96 =cut
97
98 sub end {
99  my $set = shift;
100
101  my @kids = $set->kids;
102  return undef unless @kids;
103
104  $kids[-1]->end;
105 }
106
107 LaTeX::TikZ::Interface->register(
108  union => sub {
109   shift;
110
111   __PACKAGE__->new(kids => \@_);
112  },
113 );
114
115 LaTeX::TikZ::Functor->default_rule(
116  (__PACKAGE__) => sub {
117   my ($functor, $set, @args) = @_;
118   $set->new(kids => [ map $_->$functor(@args), $set->kids ])
119  }
120 );
121
122 __PACKAGE__->meta->make_immutable;
123
124 =head1 SEE ALSO
125
126 L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>, L<LaTeX::TikZ::Set::Container>.
127
128 =head1 AUTHOR
129
130 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
131
132 You can contact me by mail or on C<irc.perl.org> (vincent).
133
134 =head1 BUGS
135
136 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>.
137 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
138
139 =head1 SUPPORT
140
141 You can find documentation for this module with the perldoc command.
142
143     perldoc LaTeX::TikZ
144
145 =head1 COPYRIGHT & LICENSE
146
147 Copyright 2010 Vincent Pit, all rights reserved.
148
149 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
150
151 =cut
152
153 1; # End of LaTeX::TikZ::Set::Union