X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet.pm;h=cf2386d85f6c62abdfb67943f2a756ca7a728c3c;hb=58ac8fce7c7d1d825f90340434ca71b1b9da843b;hp=e0886cb1bdd04560ea125857d5e774c20acde08b;hpb=3f51a1df8516c385856e6a8ae1000ed29906022f;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Set.pm b/lib/LaTeX/TikZ/Set.pm index e0886cb..cf2386d 100644 --- a/lib/LaTeX/TikZ/Set.pm +++ b/lib/LaTeX/TikZ/Set.pm @@ -9,11 +9,11 @@ LaTeX::TikZ::Set - Base role for LaTeX::TikZ set objects. =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; use Scope::Guard (); @@ -23,9 +23,13 @@ use LaTeX::TikZ::Tools; use Any::Moose 'Role'; -requires qw( - draw -); +=head1 ATTRIBUTES + +=head2 C + +Returns the list of the L objects associated with the current set. + +=cut has '_mods' => ( is => 'ro', @@ -37,6 +41,32 @@ has '_mods' => ( sub mods { @{$_[0]->_mods} } +=head1 METHODS + +This method is required by the interface : + +=over 4 + +=item * + +C + +Returns an array reference of TikZ code lines required to effectively draw the current set object, formatted by the L object C<$formatter>. + +=back + +=cut + +requires qw( + draw +); + +=head2 C + +Apply the given list of L objects to the current set. + +=cut + my $ltm_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod'); my $ltml_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Layer'); my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip'); @@ -81,7 +111,7 @@ MOD: my $tag = $mod->tag; my $old = $mods{$tag} || []; for (@$old) { - next MOD if $_->[0]->cover($mod); + next MOD if $_->[0]->covers($mod); } push @{$mods{$tag}}, [ $mod, $last_mod++, $is_layer ]; push @mods, $mod; @@ -110,27 +140,48 @@ MOD: }; } +=head2 C + +Puts the current set in the corresponding layer. +This is a shortcut for C<< $set->mod(Tikz->layer($layer)) >>. + +=cut + sub layer { - return $_[0] unless @_ > 1; + my $set = shift; - my $layer = $_[1]; + return $set unless @_; - $_[0]->mod( + my $layer = $_[0]; + $set->mod( $ltml_tc->check($layer) ? $layer : LaTeX::TikZ::Mod::Layer->new(name => $layer) ) } +=head2 C + +Clips the current set by the path given by C<$path>. +This is a shortcut for C<< $set->mod(Tikz->clip($path)) >>. + +=cut + sub clip { - return $_[0] unless @_ > 1; + my $set = shift; + + return $set unless @_; - $_[0]->mod( + $set->mod( map { $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new(clip => $_) - } @_[1 .. $#_] + } @_ ) } +=head1 SEE ALSO + +L. + =head1 AUTHOR Vincent Pit, C<< >>, L.