X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet.pm;h=505dfec1a823712e0ce06477ed39a186d4416a5c;hb=e6c6fbca8df4f8df7bbce2eb98dd260ed51d9141;hp=da636a42633ed37bd37d04d1c9126060b7a8ac39;hpb=ab352fc19c13fff9561888d8a4b951073278bd10;p=perl%2Fmodules%2FLaTeX-TikZ.git diff --git a/lib/LaTeX/TikZ/Set.pm b/lib/LaTeX/TikZ/Set.pm index da636a4..505dfec 100644 --- a/lib/LaTeX/TikZ/Set.pm +++ b/lib/LaTeX/TikZ/Set.pm @@ -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,30 @@ has '_mods' => ( sub mods { @{$_[0]->_mods} } +=head1 METHODS + +This method is required by the interface : + +=over 4 + +=item * + +C + +=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'); @@ -44,9 +72,10 @@ my $ltmc_tc = LaTeX::TikZ::Tools::type_constraint('LaTeX::TikZ::Mod::Clip'); sub mod { my $set = shift; - $ltm_tc->assert_valid($_) for @_; + my @mods = map $ltm_tc->coerce($_), @_; + $ltm_tc->assert_valid($_) for @mods; - push @{$set->_mods}, @_; + push @{$set->_mods}, @mods; $set; } @@ -55,8 +84,22 @@ sub mod { our %mods; our $last_mod = 0; - sub mods_unique { - my ($set) = @_; + around 'draw' => sub { + my ($orig, $set, $tikz) = @_; + + local $last_mod = $last_mod; + + # Save a deep copy + my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods; + my $guard = Scope::Guard->new(sub { + for (keys %mods) { + if (exists $saved_idx{$_}) { + $#{$mods{$_}} = $saved_idx{$_}; + } else { + delete $mods{$_}; + } + } + }); my (@mods, $last_layer); MOD: @@ -83,28 +126,6 @@ MOD: values %mods; } - return @mods; - } - - around 'draw' => sub { - my ($orig, $set, $tikz) = @_; - - local $last_mod = $last_mod; - - # Save a deep copy - my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods; - my $guard = Scope::Guard->new(sub { - for (keys %mods) { - if (exists $saved_idx{$_}) { - $#{$mods{$_}} = $saved_idx{$_}; - } else { - delete $mods{$_}; - } - } - }); - - my @mods = $set->mods_unique; - my $body = $set->$orig($tikz); if (@mods) { @@ -117,6 +138,13 @@ 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; @@ -128,12 +156,19 @@ sub 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; $_[0]->mod( map { - $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new($_) + $ltmc_tc->check($_) ? $_ : LaTeX::TikZ::Mod::Clip->new(clip => $_) } @_[1 .. $#_] ) }