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