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:
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) {