]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Union.pm
Rename LT::Set::Mutable to ::Container
[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 Any::Moose;
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 LaTeX::TikZ::Interface->register(
82  union => sub {
83   shift;
84
85   __PACKAGE__->new(kids => \@_);
86  },
87 );
88
89 LaTeX::TikZ::Functor->default_rule(
90  (__PACKAGE__) => sub {
91   my ($functor, $set, @args) = @_;
92   $set->new(kids => [ map $_->$functor(@args), $set->kids ])
93  }
94 );
95
96 __PACKAGE__->meta->make_immutable;
97
98 =head1 SEE ALSO
99
100 L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>, L<LaTeX::TikZ::Set::Container>.
101
102 =head1 AUTHOR
103
104 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
105
106 You can contact me by mail or on C<irc.perl.org> (vincent).
107
108 =head1 BUGS
109
110 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>.
111 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
112
113 =head1 SUPPORT
114
115 You can find documentation for this module with the perldoc command.
116
117     perldoc LaTeX::TikZ
118
119 =head1 COPYRIGHT & LICENSE
120
121 Copyright 2010 Vincent Pit, all rights reserved.
122
123 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
124
125 =cut
126
127 1; # End of LaTeX::TikZ::Set::Union