]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Sequence.pm
7742435548c12366c2a0385d2f4808fc551977ad
[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.01
13
14 =cut
15
16 our $VERSION = '0.01';
17
18 use List::Util ();
19
20 use LaTeX::TikZ::Scope;
21
22 use Any::Moose;
23 use Any::Moose 'Util::TypeConstraints'
24                => [ qw/subtype as where find_type_constraint/ ];
25
26 with qw(
27  LaTeX::TikZ::Set
28  LaTeX::TikZ::Set::Mutable
29 );
30
31 subtype 'LaTeX::TikZ::Set::Sequence::Elements'
32      => as 'Object'
33      => where {
34              $_->does('LaTeX::TikZ::Set::Op')
35           or $_->isa('LaTeX::TikZ::Set::Sequence')
36           or $_->isa('LaTeX::TikZ::Set::Mod')
37      };
38
39 has '_kids' => (
40  is       => 'ro',
41  isa      => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Sequence::Elements]]',
42  init_arg => 'kids',
43  default  => sub { [ ] },
44 );
45
46 sub kids { @{$_[0]->_kids} }
47
48 my $ltsse_tc = find_type_constraint('LaTeX::TikZ::Set::Sequence::Elements');
49
50 sub add {
51  my $set = shift;
52
53  $ltsse_tc->assert_valid($_) for @_;
54
55  push @{$set->_kids}, @_;
56
57  $set;
58 }
59
60 sub draw {
61  my $set = shift;
62
63  List::Util::reduce { LaTeX::TikZ::Scope::fold($a, $b) }
64   map $_->draw(@_),
65    $set->kids;
66 }
67
68 use LaTeX::TikZ::API seq => sub {
69  shift;
70
71  __PACKAGE__->new(kids => \@_);
72 };
73
74 __PACKAGE__->meta->make_immutable;
75
76 =head1 AUTHOR
77
78 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
79
80 You can contact me by mail or on C<irc.perl.org> (vincent).
81
82 =head1 BUGS
83
84 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>.
85 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
86
87 =head1 SUPPORT
88
89 You can find documentation for this module with the perldoc command.
90
91     perldoc LaTeX::TikZ
92
93 =head1 COPYRIGHT & LICENSE
94
95 Copyright 2010 Vincent Pit, all rights reserved.
96
97 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
98
99 =cut
100
101 1; # End of LaTeX::TikZ::Set::Sequence