mro#
MRO (Method Resolution Order) implementation
Provides DFS and C3 linearization of class hierarchies, matching
the behaviour of perl5’s mro core module (mro.xs).
Public API:
get_linear_isa(class [, "dfs"|"c3"])— recursive linearizationset_mro(class, "dfs"|"c3")— per-class MRO preferenceget_mro(class)— return stored preference (default “dfs”)get_isarev(class)— reverse @ISA index (computed on-the-fly)get_pkg_gen(class)— generation counter (per-package, real tracking)is_universal(class)— true only for “UNIVERSAL”method_changed_in/invalidate_all_method_caches— cache invalidation
Perl equivalent: mro (XS core module)
Functions#
get_linear_isa#
Returns the linearized @ISA for a class using DFS (default) or C3 algorithm.
use mro;
my $isa = mro::get_linear_isa('MyClass'); # DFS
my $isa = mro::get_linear_isa('MyClass', 'c3'); # C3
set_mro#
Sets the MRO algorithm for a class. Valid values: "dfs", "c3".
use mro;
mro::set_mro('MyClass', 'c3');
get_mro#
Returns the stored MRO algorithm name for a class (defaults to "dfs").
use mro;
my $type = mro::get_mro('MyClass'); # "dfs" or "c3"
get_isarev#
Returns an arrayref of classes that directly or indirectly inherit from the given class (reverse @ISA index, computed on the fly).
use mro;
my $subclasses = mro::get_isarev('BaseClass');
get_pkg_gen#
Returns the per-package generation counter. Bumped on each define_sub
or method_changed_in call. Returns 0 for non-existent packages, 1 for
packages with no explicit counter yet.
use mro;
my $gen = mro::get_pkg_gen('MyClass');
is_universal#
Returns true only if the given class is "UNIVERSAL".
use mro;
my $ok = mro::is_universal('UNIVERSAL'); # 1
method_changed_in#
Bumps the generation counter for the given class and invalidates all CV caches. Call when method resolution may have changed.
use mro;
mro::method_changed_in('MyClass');
invalidate_all_method_caches#
Clears the entire CV cache without targeting a specific class.
use mro;
mro::invalidate_all_method_caches();
import#
Called implicitly by use mro 'c3'. Sets the MRO algorithm for the
calling package.
use mro 'c3'; # sets C3 for current package