} 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 {