1PERLMROAPI(1) Perl Programmers Reference Guide PERLMROAPI(1)
2
3
4
6 perlmroapi - Perl method resolution plugin interface
7
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 with "Perl_mro_register" by
15 providing the following structure
16
17 struct mro_alg {
18 AV *(*resolve)(pTHX_ HV *stash, U32 level);
19 const char *name;
20 U16 length;
21 U16 kflags;
22 U32 hash;
23 };
24
25 resolve
26 Pointer to the linearisation function, described below.
27
28 name
29 Name of the MRO, either in ISO-8859-1 or UTF-8.
30
31 length
32 Length of the name.
33
34 kflags
35 If the name is given in UTF-8, set this to "HVhek_UTF8". The value
36 is passed direct as the parameter kflags to "hv_common()".
37
38 hash
39 A precomputed hash value for the MRO's name, or 0.
40
42 The "resolve" function is called to generate a linearised ISA for the
43 given stash, using this MRO. It is called with a pointer to the stash,
44 and a level of 0. The core always sets level to 0 when it calls your
45 function - the parameter is provided to allow your implementation to
46 track depth if it needs to recurse.
47
48 The function should return a reference to an array containing the
49 parent classes in order. The caller is responsible for incrementing the
50 reference count if it wants to keep the structure. Hence if you have
51 created a temporary value that you keep no pointer to, "sv_2mortal()"
52 to ensure that it is disposed of correctly. If you have cached your
53 return value, then return a pointer to it without changing the
54 reference count.
55
57 Computing MROs can be expensive. The implementation provides a cache,
58 in which you can store a single "SV *", or anything that can be cast to
59 "SV *", such as "AV *". To read your private value, use the macro
60 "MRO_GET_PRIVATE_DATA()", passing it the "mro_meta" structure from the
61 stash, and a pointer to your "mro_alg" structure:
62
63 meta = HvMROMETA(stash);
64 private_sv = MRO_GET_PRIVATE_DATA(meta, &my_mro_alg);
65
66 To set your private value, call "Perl_mro_set_private_data()":
67
68 Perl_mro_set_private_data(aTHX_ meta, &c3_alg, private_sv);
69
70 The private data cache will take ownership of a reference to
71 private_sv, much the same way that "hv_store()" takes ownership of a
72 reference to the value that you pass it.
73
75 For examples of MRO implementations, see "S_mro_get_linear_isa_c3()"
76 and the "BOOT:" section of mro/mro.xs, and "S_mro_get_linear_isa_dfs()"
77 in mro.c
78
80 The implementation of the C3 MRO and switchable MROs within the perl
81 core was written by Brandon L Black. Nicholas Clark created the
82 pluggable interface, refactored Brandon's implementation to work with
83 it, and wrote this document.
84
85
86
87perl v5.10.1 2009-06-27 PERLMROAPI(1)