1 package LaTeX::TikZ::Set;
8 LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects.
16 our $VERSION = '0.01';
20 use LaTeX::TikZ::Scope;
22 use LaTeX::TikZ::Tools;
24 use Any::Moose 'Role';
32 isa => 'Maybe[ArrayRef[LaTeX::TikZ::Mod]]',
34 default => sub { [ ] },
38 sub mods { @{$_[0]->_mods} }
40 my $ltm_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod');
41 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
42 my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');
48 map { $ltm_tc->check($_) ? $_ : $ltm_tc->coerce($_) }
61 my (@mods, $last_layer);
63 for my $mod ($set->mods) {
64 my $is_layer = $ltml_tc->check($mod);
65 $last_layer = $mod if $is_layer;
67 my $old = $mods{$tag} || [];
69 next MOD if $_->[0]->cover($mod);
71 push @{$mods{$tag}}, [ $mod, $last_mod++, $is_layer ];
76 # Clips and mods don't propagate through layers. Hence if a layer is set,
79 push @mods, map $_->[0],
80 sort { $a->[1] <=> $b->[1] }
89 around 'draw' => sub {
90 my ($orig, $set, $tikz) = @_;
92 local $last_mod = $last_mod;
95 my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods;
96 my $guard = Scope::Guard->new(sub {
98 if (exists $saved_idx{$_}) {
99 $#{$mods{$_}} = $saved_idx{$_};
106 my @mods = $set->mods_unique;
108 my $body = $set->$orig($tikz);
111 $body = LaTeX::TikZ::Scope->new
112 ->mod(map $_->apply($tikz), @mods)
121 return $_[0] unless @_ > 1;
126 $ltml_tc->check($layer) ? $layer
127 : LaTeX::TikZ::Mod::Layer->new(name => $layer)
132 return $_[0] unless @_ > 1;
136 $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new($_)
143 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
145 You can contact me by mail or on C<irc.perl.org> (vincent).
149 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>.
150 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
154 You can find documentation for this module with the perldoc command.
158 =head1 COPYRIGHT & LICENSE
160 Copyright 2010 Vincent Pit, all rights reserved.
162 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
166 1; # End of LaTeX::TikZ::Set