1 package LaTeX::TikZ::Set::Mod;
8 LaTeX::TikZ::Set::Mod - A set object that stores modifiers to be applied underneath.
16 our $VERSION = '0.01';
20 use LaTeX::TikZ::Tools;
22 use LaTeX::TikZ::Scope;
28 LaTeX::TikZ::Set::Mutable
33 does => 'LaTeX::TikZ::Set',
38 sub set { $_[0]->_set }
43 isa => 'Maybe[ArrayRef[LaTeX::TikZ::Mod]]',
45 default => sub { [ ] },
48 sub mods { @{$_[0]->_mods} }
50 my $ltm_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod');
51 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
57 map { $ltm_tc->check($_) ? $_ : $ltm_tc->coerce($_) }
67 if ($kid->does('LaTeX::TikZ::Set::Mutable')) {
70 require LaTeX::TikZ::Set::Sequence;
71 $set->_set(LaTeX::TikZ::Set::Sequence->new(
86 my (@mods, $has_layer);
88 for my $mod ($set->mods) {
89 $has_layer = 1 if $ltml_tc->check($mod);
93 my $old = $mods{$tag};
94 @candidates = $old ? map $_->[0], @$old : ();
96 @candidates = values %mods;
98 $_->cover($mod) and next MOD for @candidates;
99 push @{$mods{$tag}}, [ $mod, $last_mod++ ];
104 # Clips and mods don't propagate through layers. Hence if a layer is set,
106 @mods = map $_->[0], sort { $a->[1] <=> $b->[1] } map @$_, values %mods;
113 my ($set, $tikz) = @_;
115 local $last_mod = $last_mod;
118 my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods;
119 my $guard = Scope::Guard->new(sub {
121 if (exists $saved_idx{$_}) {
122 $#{$mods{$_}} = $saved_idx{$_};
129 my @mods = $set->mods_unique;
131 LaTeX::TikZ::Scope->new
132 ->mod(map $_->apply($tikz), @mods)
133 ->body($set->_set->draw($tikz))
137 __PACKAGE__->meta->make_immutable;
141 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
143 You can contact me by mail or on C<irc.perl.org> (vincent).
147 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>.
148 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
152 You can find documentation for this module with the perldoc command.
156 =head1 COPYRIGHT & LICENSE
158 Copyright 2010 Vincent Pit, all rights reserved.
160 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
164 1; # End of LaTeX::TikZ::Set::Mod