From: Vincent Pit Date: Wed, 21 Jul 2010 17:25:32 +0000 (+0200) Subject: Only declare once each mod, tag-wise X-Git-Tag: v0.01~20 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c09a50b51230b49b80114d2bd5a3c0a7250c6bf9;p=perl%2Fmodules%2FLaTeX-TikZ.git Only declare once each mod, tag-wise --- diff --git a/lib/LaTeX/TikZ/Formatter.pm b/lib/LaTeX/TikZ/Formatter.pm index b3c242a..0838e46 100644 --- a/lib/LaTeX/TikZ/Formatter.pm +++ b/lib/LaTeX/TikZ/Formatter.pm @@ -65,29 +65,42 @@ sub id { } qw/unit format scale width height origin/; } -my $find_mods; -$find_mods = do { - no warnings 'recursion'; +my $find_mods = do { + our %seen; - Sub::Name::subname('find_mods' => sub { - my ($set, $layers, $others) = @_; + my $find_mods_rec; + $find_mods_rec = do { + no warnings 'recursion'; + + Sub::Name::subname('find_mods_rec' => sub { + my ($set, $layers, $others) = @_; + + for ($set->mods) { + my $tag = $_->tag; + next if $seen{$tag}++; - for ($set->mods) { - if ($_->isa('LaTeX::TikZ::Mod::Layer')) { - push @$layers, $_; - } else { - push @$others, $_; + if ($_->isa('LaTeX::TikZ::Mod::Layer')) { + push @$layers, $_; + } else { + push @$others, $_; + } } - } - my @subsets = $set->isa('LaTeX::TikZ::Set::Sequence') - ? $set->kids - : $set->isa('LaTeX::TikZ::Set::Path') - ? $set->ops - : (); + my @subsets = $set->isa('LaTeX::TikZ::Set::Sequence') + ? $set->kids + : $set->isa('LaTeX::TikZ::Set::Path') + ? $set->ops + : (); + + $find_mods_rec->($_, $layers, $others) for @subsets; + }); + }; + + Sub::Name::subname('find_mods' => sub { + local %seen = (); - $find_mods->($_, $layers, $others) for @subsets; - }) + $find_mods_rec->(@_); + }); }; sub render {