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, $has_layer);
63 for my $mod ($set->mods) {
64 $has_layer = 1 if $ltml_tc->check($mod);
66 my $old = $mods{$tag} || [];
68 next MOD if $_->[0]->cover($mod);
70 push @{$mods{$tag}}, [ $mod, $last_mod++ ];
75 # Clips and mods don't propagate through layers. Hence if a layer is set,
77 @mods = map $_->[0], sort { $a->[1] <=> $b->[1] } map @$_, values %mods;
83 around 'draw' => sub {
84 my ($orig, $set, $tikz) = @_;
86 local $last_mod = $last_mod;
89 my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods;
90 my $guard = Scope::Guard->new(sub {
92 if (exists $saved_idx{$_}) {
93 $#{$mods{$_}} = $saved_idx{$_};
100 my @mods = $set->mods_unique;
102 my $body = $set->$orig($tikz);
105 $body = LaTeX::TikZ::Scope->new
106 ->mod(map $_->apply($tikz), @mods)
115 return $_[0] unless @_ > 1;
120 $ltml_tc->check($layer) ? $layer
121 : LaTeX::TikZ::Mod::Layer->new(name => $layer)
126 return $_[0] unless @_ > 1;
130 $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new($_)
137 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
139 You can contact me by mail or on C<irc.perl.org> (vincent).
143 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>.
144 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
148 You can find documentation for this module with the perldoc command.
152 =head1 COPYRIGHT & LICENSE
154 Copyright 2010 Vincent Pit, all rights reserved.
156 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
160 1; # End of LaTeX::TikZ::Set