3 perlmroapi - Perl method resolution plugin interface
7 As of Perl 5.10.1 there is a new interface for plugging and using method
8 resolution orders other than the default (linear depth first search).
9 The C3 method resolution order added in 5.10.0 has been re-implemented as
10 a plugin, without changing its Perl-space interface.
12 Each plugin should register itself with C<Perl_mro_register> by providing
13 the following structure
16 AV *(*resolve)(pTHX_ HV *stash, U32 level);
27 Pointer to the linearisation function, described below.
31 Name of the MRO, either in ISO-8859-1 or UTF-8.
39 If the name is given in UTF-8, set this to C<HVhek_UTF8>. The value is passed
40 direct as the parameter I<kflags> to C<hv_common()>.
44 A precomputed hash value for the MRO's name, or 0.
50 The C<resolve> function is called to generate a linearised ISA for the
51 given stash, using this MRO. It is called with a pointer to the stash, and
52 a I<level> of 0. The core always sets I<level> to 0 when it calls your
53 function - the parameter is provided to allow your implementation to track
54 depth if it needs to recurse.
56 The function should return a reference to an array containing the parent
57 classes in order. The caller is responsible for incrementing the reference
58 count if it wants to keep the structure. Hence if you have created a
59 temporary value that you keep no pointer to, C<sv_2mortal()> to ensure that
60 it is disposed of correctly. If you have cached your return value, then
61 return a pointer to it without changing the reference count.
65 Computing MROs can be expensive. The implementation provides a cache, in
66 which you can store a single C<SV *>, or anything that can be cast to
67 C<SV *>, such as C<AV *>. To read your private value, use the macro
68 C<MRO_GET_PRIVATE_DATA()>, passing it the C<mro_meta> structure from the
69 stash, and a pointer to your C<mro_alg> structure:
71 meta = HvMROMETA(stash);
72 private_sv = MRO_GET_PRIVATE_DATA(meta, &my_mro_alg);
74 To set your private value, call C<Perl_mro_set_private_data()>:
76 Perl_mro_set_private_data(aTHX_ meta, &c3_alg, private_sv);
78 The private data cache will take ownership of a reference to private_sv,
79 much the same way that C<hv_store()> takes ownership of a reference to the
80 value that you pass it.
84 For examples of MRO implementations, see C<S_mro_get_linear_isa_c3()>
85 and the C<BOOT:> section of F<mro/mro.xs>, and C<S_mro_get_linear_isa_dfs()>
90 The implementation of the C3 MRO and switchable MROs within the perl core was
91 written by Brandon L Black. Nicholas Clark created the pluggable interface,
92 refactored Brandon's implementation to work with it, and wrote this document.