1 package LaTeX::TikZ::Context;
8 LaTeX::TikZ::Context - An object modeling in which context a set is evaluated.
16 our $VERSION = '0.02';
18 use LaTeX::TikZ::Mod (); # Required to work around a bug in Mouse
20 use LaTeX::TikZ::Tools;
28 The parent context of the current one, or C<undef> for the topmost context.
34 isa => 'Maybe[LaTeX::TikZ::Context]',
41 The list of mods that are asked to be applied in this context.
47 isa => 'ArrayRef[LaTeX::TikZ::Mod]',
49 default => sub { [ ] },
53 sub mods { @{$_[0]->_mods} }
55 has '_applied_mods' => (
57 isa => 'HashRef[LaTeX::TikZ::Mod]',
59 default => sub { { } },
63 =head2 C<effective_mods>
65 The list of mods that actually need to be applied in this context.
69 has '_effective_mods' => (
71 isa => 'ArrayRef[LaTeX::TikZ::Mod]',
73 default => sub { [ ] },
77 sub effective_mods { @{$_[0]->_effective_mods} }
87 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
91 my $pcxt = $cxt->parent;
93 my $applied_mods = $cxt->_applied_mods;
94 for (my $c = $pcxt; defined $c; $c = $c->parent) {
95 my $mods = $c->_applied_mods;
96 while (my ($tag, $mods_info) = each %$mods) {
97 unshift @{$applied_mods->{$tag}}, @$mods_info;
101 my $last_mod = defined $pcxt ? $pcxt->_last_mod : 0;
102 my $effective_mods = $cxt->_effective_mods;
107 for my $mod ($cxt->mods) {
108 my $is_layer = $ltml_tc->check($mod);
109 $last_layer = $mod if $is_layer;
112 my $old = $applied_mods->{$tag} || [];
114 next MOD if $_->[0]->covers($mod);
117 push @{$applied_mods->{$tag}}, [ $mod, $last_mod++, $is_layer ];
118 push @$effective_mods, $mod;
122 # Clips and mods don't propagate through layers. Hence, if a layer is set,
123 # we should force their reuse.
124 @$effective_mods = $last_layer;
125 push @$effective_mods, map $_->[0],
126 sort { $a->[1] <=> $b->[1] }
129 values %$applied_mods;
132 $cxt->_last_mod($last_mod);
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,2011,2012,2013,2014,2015 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::Context