1PERLMROAPI(1)          Perl Programmers Reference Guide          PERLMROAPI(1)
2
3
4

NAME

6       perlmroapi - Perl method resolution plugin interface
7

DESCRIPTION

9       As of Perl 5.10.1 there is a new interface for plugging and using
10       method resolution orders other than the default (linear depth first
11       search).  The C3 method resolution order added in 5.10.0 has been re-
12       implemented as a plugin, without changing its Perl-space interface.
13
14       Each plugin should register itself by providing the following structure
15
16           struct mro_alg {
17               AV *(*resolve)(pTHX_ HV *stash, U32 level);
18               const char *name;
19               U16 length;
20               U16 kflags;
21               U32 hash;
22           };
23
24       and calling "Perl_mro_register":
25
26           Perl_mro_register(aTHX_ &my_mro_alg);
27
28       resolve
29           Pointer to the linearisation function, described below.
30
31       name
32           Name of the MRO, either in ISO-8859-1 or UTF-8.
33
34       length
35           Length of the name.
36
37       kflags
38           If the name is given in UTF-8, set this to "HVhek_UTF8". The value
39           is passed direct as the parameter kflags to "hv_common()".
40
41       hash
42           A precomputed hash value for the MRO's name, or 0.
43

Callbacks

45       The "resolve" function is called to generate a linearised ISA for the
46       given stash, using this MRO. It is called with a pointer to the stash,
47       and a level of 0. The core always sets level to 0 when it calls your
48       function - the parameter is provided to allow your implementation to
49       track depth if it needs to recurse.
50
51       The function should return a reference to an array containing the
52       parent classes in order. The names of the classes should be the result
53       of calling "HvENAME()" on the stash. In those cases where "HvENAME()"
54       returns null, "HvNAME()" should be used instead.
55
56       The caller is responsible for incrementing the reference count of the
57       array returned if it wants to keep the structure. Hence, if you have
58       created a temporary value that you keep no pointer to, "sv_2mortal()"
59       to ensure that it is disposed of correctly. If you have cached your
60       return value, then return a pointer to it without changing the
61       reference count.
62

Caching

64       Computing MROs can be expensive. The implementation provides a cache,
65       in which you can store a single "SV *", or anything that can be cast to
66       "SV *", such as "AV *". To read your private value, use the macro
67       "MRO_GET_PRIVATE_DATA()", passing it the "mro_meta" structure from the
68       stash, and a pointer to your "mro_alg" structure:
69
70           meta = HvMROMETA(stash);
71           private_sv = MRO_GET_PRIVATE_DATA(meta, &my_mro_alg);
72
73       To set your private value, call "Perl_mro_set_private_data()":
74
75           Perl_mro_set_private_data(aTHX_ meta, &c3_alg, private_sv);
76
77       The private data cache will take ownership of a reference to
78       private_sv, much the same way that "hv_store()" takes ownership of a
79       reference to the value that you pass it.
80

Examples

82       For examples of MRO implementations, see "S_mro_get_linear_isa_c3()"
83       and the "BOOT:" section of ext/mro/mro.xs, and
84       "S_mro_get_linear_isa_dfs()" in mro_core.c
85

AUTHORS

87       The implementation of the C3 MRO and switchable MROs within the perl
88       core was written by Brandon L Black. Nicholas Clark created the
89       pluggable interface, refactored Brandon's implementation to work with
90       it, and wrote this document.
91
92
93
94perl v5.30.2                      2020-03-27                     PERLMROAPI(1)
Impressum