1 package LaTeX::TikZ::Set;
8 LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects.
16 our $VERSION = '0.02';
18 use LaTeX::TikZ::Context;
19 use LaTeX::TikZ::Scope;
21 use LaTeX::TikZ::Tools;
29 Returns the list of the L<LaTeX::TikZ::Mod> objects associated with the current set.
35 isa => 'Maybe[ArrayRef[LaTeX::TikZ::Mod]]',
37 default => sub { [ ] },
41 sub mods { @{$_[0]->_mods} }
45 This method is required by the interface :
51 C<draw $formatter, $context>
53 Returns an array reference of TikZ code lines required to effectively draw the current set object, formatted by the L<LaTeX::TikZ::Formatter> object C<$formatter>.
54 The current evaluation context is passed as the L<LaTeX::TikZ::Context> object C<$context>.
66 Apply the given list of L<LaTeX::TikZ::Mod> objects to the current set.
70 my $ltm_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod');
71 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
72 my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');
77 my @mods = map $ltm_tc->coerce($_), @_;
78 $ltm_tc->assert_valid($_) for @mods;
80 push @{$set->_mods}, @mods;
85 around 'draw' => sub {
86 my ($orig, $set, $tikz, $pcxt) = @_;
88 my $cxt = LaTeX::TikZ::Context->new(
90 mods => [ $set->mods ],
93 my $body = $set->$orig($tikz, $cxt);
95 my @mods = $cxt->effective_mods;
97 $body = LaTeX::TikZ::Scope->new(
98 mods => [ map $_->apply($tikz), @mods ],
106 =head2 C<layer $layer>
108 Puts the current set in the corresponding layer.
109 This is a shortcut for C<< $set->mod(Tikz->layer($layer)) >>.
116 return $set unless @_;
120 $ltml_tc->check($layer) ? $layer
121 : LaTeX::TikZ::Mod::Layer->new(name => $layer)
127 Clips the current set by the path given by C<$path>.
128 This is a shortcut for C<< $set->mod(Tikz->clip($path)) >>.
135 return $set unless @_;
139 $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new(clip => $_)
150 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
152 You can contact me by mail or on C<irc.perl.org> (vincent).
156 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>.
157 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
161 You can find documentation for this module with the perldoc command.
165 =head1 COPYRIGHT & LICENSE
167 Copyright 2010 Vincent Pit, all rights reserved.
169 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
173 1; # End of LaTeX::TikZ::Set