X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet%2FSequence.pm;h=70176a1fb65c061a298a792e9b5001906cc004d5;hp=3f14bb7a78a4dba17f6364eaed1e00315436499b;hb=1c53f7e28198adfb2905667acd5741f163832d7b;hpb=e8f0879ade07eed4f58cd52c0771f4e1ecc90b09 diff --git a/lib/LaTeX/TikZ/Set/Sequence.pm b/lib/LaTeX/TikZ/Set/Sequence.pm index 3f14bb7..70176a1 100644 --- a/lib/LaTeX/TikZ/Set/Sequence.pm +++ b/lib/LaTeX/TikZ/Set/Sequence.pm @@ -9,31 +9,49 @@ LaTeX::TikZ::Set::Sequence - A set object grouping a sequence of objects. =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; use List::Util (); +use LaTeX::TikZ::Scope; + +use LaTeX::TikZ::Interface; +use LaTeX::TikZ::Functor; + use Any::Moose; use Any::Moose 'Util::TypeConstraints' - => [ qw/subtype as where find_type_constraint/ ]; + => [ qw ]; + +=head1 RELATIONSHIPS + +This class consumes the L and L roles, and as such implements the L, L and L methods. + +=cut -with qw( +with qw< LaTeX::TikZ::Set - LaTeX::TikZ::Set::Mutable -); + LaTeX::TikZ::Set::Container +>; subtype 'LaTeX::TikZ::Set::Sequence::Elements' => as 'Object' => where { - $_->does('LaTeX::TikZ::Set::Op') + $_->does('LaTeX::TikZ::Set::Path') or $_->isa('LaTeX::TikZ::Set::Sequence') - or $_->isa('LaTeX::TikZ::Set::Mod') }; +=head1 ATTRIBUTES + +=head2 C + +The L or L objects that from the sequence. + +=cut + has '_kids' => ( is => 'ro', isa => 'Maybe[ArrayRef[LaTeX::TikZ::Set::Sequence::Elements]]', @@ -43,6 +61,12 @@ has '_kids' => ( sub kids { @{$_[0]->_kids} } +=head1 METHODS + +=head2 C + +=cut + my $ltsse_tc = find_type_constraint('LaTeX::TikZ::Set::Sequence::Elements'); sub add { @@ -55,22 +79,42 @@ sub add { $set; } +=head2 C + +=cut + sub draw { my $set = shift; - List::Util::reduce { $a . $b } map $_->draw(@_), $set->kids; + my @kids = $set->kids; + return [ ] unless @kids; + + List::Util::reduce { LaTeX::TikZ::Scope::fold($a, $b) } + map $_->draw(@_), + @kids; } -use LaTeX::TikZ::API seq => sub { - shift; +LaTeX::TikZ::Interface->register( + seq => sub { + shift; - die 'wut' if $_[0]->isa('LaTeX::TikZ::Set::Op'); + __PACKAGE__->new(kids => \@_); + }, +); - __PACKAGE__->new(kids => \@_); -}; +LaTeX::TikZ::Functor->default_rule( + (__PACKAGE__) => sub { + my ($functor, $set, @args) = @_; + $set->new(kids => [ map $_->$functor(@args), $set->kids ]) + } +); __PACKAGE__->meta->make_immutable; +=head1 SEE ALSO + +L, L, L. + =head1 AUTHOR Vincent Pit, C<< >>, L.