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