1 package LaTeX::TikZ::Set;
8 LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects.
16 our $VERSION = '0.03';
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>.
68 Apply the given list of L<LaTeX::TikZ::Mod> objects to the current set.
72 my $ltm_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod');
73 my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer');
74 my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip');
79 my @mods = map $ltm_tc->coerce($_), @_;
80 $ltm_tc->assert_valid($_) for @mods;
82 push @{$set->_mods}, @mods;
87 around 'draw' => sub {
88 my ($orig, $set, $tikz, $pcxt) = @_;
90 my $cxt = LaTeX::TikZ::Context->new(
92 mods => [ $set->mods ],
95 my $body = $set->$orig($tikz, $cxt);
97 my @mods = $cxt->effective_mods;
99 $body = LaTeX::TikZ::Scope->new(
100 mods => [ map $_->apply($tikz), @mods ],
112 Puts the current set in the corresponding layer.
113 This is a shortcut for C<< $set->mod(Tikz->layer($layer)) >>.
120 return $set unless @_;
124 $ltml_tc->check($layer) ? $layer
125 : LaTeX::TikZ::Mod::Layer->new(name => $layer)
133 Clips the current set by the path given by C<$path>.
134 This is a shortcut for C<< $set->mod(Tikz->clip($path)) >>.
141 return $set unless @_;
145 $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new(clip => $_)
156 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
158 You can contact me by mail or on C<irc.perl.org> (vincent).
162 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>.
163 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
167 You can find documentation for this module with the perldoc command.
171 =head1 COPYRIGHT & LICENSE
173 Copyright 2010,2011,2012,2013,2014,2015 Vincent Pit, all rights reserved.
175 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
179 1; # End of LaTeX::TikZ::Set