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