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';
30 Returns the list of the L<LaTeX::TikZ::Mod> objects associated with the current set.
36 isa => 'Maybe[ArrayRef[LaTeX::TikZ::Mod]]',
38 default => sub { [ ] },
42 sub mods { @{$_[0]->_mods} }
46 This method is required by the interface :
64 Apply the given list of L<LaTeX::TikZ::Mod> objects to the current set.
68 my $ltm_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod');
69 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
70 my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');
75 my @mods = map $ltm_tc->coerce($_), @_;
76 $ltm_tc->assert_valid($_) for @mods;
78 push @{$set->_mods}, @mods;
87 around 'draw' => sub {
88 my ($orig, $set, $tikz) = @_;
90 local $last_mod = $last_mod;
93 my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods;
94 my $guard = Scope::Guard->new(sub {
96 if (exists $saved_idx{$_}) {
97 $#{$mods{$_}} = $saved_idx{$_};
104 my (@mods, $last_layer);
106 for my $mod ($set->mods) {
107 my $is_layer = $ltml_tc->check($mod);
108 $last_layer = $mod if $is_layer;
110 my $old = $mods{$tag} || [];
112 next MOD if $_->[0]->cover($mod);
114 push @{$mods{$tag}}, [ $mod, $last_mod++, $is_layer ];
119 # Clips and mods don't propagate through layers. Hence if a layer is set,
122 push @mods, map $_->[0],
123 sort { $a->[1] <=> $b->[1] }
129 my $body = $set->$orig($tikz);
132 $body = LaTeX::TikZ::Scope->new
133 ->mod(map $_->apply($tikz), @mods)
141 =head2 C<layer $layer>
143 Puts the current set in the corresponding layer.
144 This is a shortcut for C<< $set->mod(Tikz->layer($layer)) >>.
149 return $_[0] unless @_ > 1;
154 $ltml_tc->check($layer) ? $layer
155 : LaTeX::TikZ::Mod::Layer->new(name => $layer)
161 Clips the current set by the path given by C<$path>.
162 This is a shortcut for C<< $set->mod(Tikz->clip($path)) >>.
167 return $_[0] unless @_ > 1;
171 $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new(clip => $_)
182 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
184 You can contact me by mail or on C<irc.perl.org> (vincent).
188 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>.
189 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
193 You can find documentation for this module with the perldoc command.
197 =head1 COPYRIGHT & LICENSE
199 Copyright 2010 Vincent Pit, all rights reserved.
201 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
205 1; # End of LaTeX::TikZ::Set