Vincent notes that doing it at the start is fragile, as it assumes that the
flush doesn't actively build any new caches, merely clear existing caches.
Right now the flush only clears, but why rely on it when not doing so is easy?
my $constants;
my $multiple = ref $_[0];
my $pkg = caller;
- my $done_mro;
+ my $flush_mro;
my $symtab;
if (_CAN_PCS) {
# constants from cv_const_sv are read only. So we have to:
Internals::SvREADONLY($scalar, 1);
$symtab->{$name} = \$scalar;
- # No need to flush the cache if we've just flushed it.
- mro::method_changed_in($pkg) unless $done_mro++;
+ ++$flush_mro;
} else {
*$full_name = sub () { $scalar };
}
}
}
}
+ # Flush the cache exactly once if we make any direct symbol table changes.
+ mro::method_changed_in($pkg) if $flush_mro++;
}
1;