Debian Codegraph @

upstream/fedora-44/man1/perlmroapi.1

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "PERLMROAPI 1"
61 .TH PERLMROAPI 1 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 perlmroapi \- Perl method resolution plugin interface
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 As of Perl 5.10.1 there is a new interface for plugging and using method
71 resolution orders other than the default (linear depth first search).
72 The C3 method resolution order added in 5.10.0 has been re\-implemented as
73 a plugin, without changing its Perl\-space interface.
74 .PP
75 Each plugin should register itself by providing
76 the following structure
77 .PP
78 .Vb 7
79 \& struct mro_alg {
80 \& AV *(*resolve)(pTHX_ HV *stash, U32 level);
81 \& const char *name;
82 \& U16 length;
83 \& U16 kflags;
84 \& U32 hash;
85 \& };
86 .Ve
87 .PP
88 and calling \f(CW\*(C`Perl_mro_register\*(C'\fR:
89 .PP
90 .Vb 1
91 \& Perl_mro_register(aTHX_ &my_mro_alg);
92 .Ve
93 .IP resolve 4
94 .IX Item "resolve"
95 Pointer to the linearisation function, described below.
96 .IP name 4
97 .IX Item "name"
98 Name of the MRO, either in ISO\-8859\-1 or UTF\-8.
99 .IP length 4
100 .IX Item "length"
101 Length of the name.
102 .IP kflags 4
103 .IX Item "kflags"
104 If the name is given in UTF\-8, set this to \f(CW\*(C`HVhek_UTF8\*(C'\fR. The value is passed
105 direct as the parameter \fIkflags\fR to \f(CWhv_common()\fR.
106 .IP hash 4
107 .IX Item "hash"
108 A precomputed hash value for the MRO\*(Aqs name, or 0.
109 .SH Callbacks
110 .IX Header "Callbacks"
111 The \f(CW\*(C`resolve\*(C'\fR function is called to generate a linearised ISA for the
112 given stash, using this MRO. It is called with a pointer to the stash, and
113 a \fIlevel\fR of 0. The core always sets \fIlevel\fR to 0 when it calls your
114 function \- the parameter is provided to allow your implementation to track
115 depth if it needs to recurse.
116 .PP
117 The function should return a reference to an array containing string SVs
118 giving the names of parent classes in order. The names of the classes should
119 be the result of calling \f(CWHvENAME()\fR on the stash. In those cases where
120 \&\f(CWHvENAME()\fR returns null, \f(CWHvNAME()\fR should be used instead.
121 .PP
122 The caller is responsible for incrementing the reference count of the array
123 returned if it wants to keep the structure. Hence, if you have created a
124 temporary value that you keep no pointer to, \f(CWsv_2mortal()\fR to ensure that
125 it is disposed of correctly. If you have cached your return value, then
126 return a pointer to it without changing the reference count.
127 .SH Caching
128 .IX Header "Caching"
129 Computing MROs can be expensive. The implementation provides a cache, in
130 which you can store a single \f(CW\*(C`SV *\*(C'\fR, or anything that can be cast to
131 \&\f(CW\*(C`SV *\*(C'\fR, such as \f(CW\*(C`AV *\*(C'\fR. To read your private value, use the macro
132 \&\f(CWMRO_GET_PRIVATE_DATA()\fR, passing it the \f(CW\*(C`mro_meta\*(C'\fR structure from the
133 stash, and a pointer to your \f(CW\*(C`mro_alg\*(C'\fR structure:
134 .PP
135 .Vb 2
136 \& meta = HvMROMETA(stash);
137 \& private_sv = MRO_GET_PRIVATE_DATA(meta, &my_mro_alg);
138 .Ve
139 .PP
140 To set your private value, call \f(CWPerl_mro_set_private_data()\fR:
141 .PP
142 .Vb 1
143 \& Perl_mro_set_private_data(aTHX_ meta, &c3_alg, private_sv);
144 .Ve
145 .PP
146 The private data cache will take ownership of a reference to private_sv,
147 much the same way that \f(CWhv_store()\fR takes ownership of a reference to the
148 value that you pass it.
149 .SH Examples
150 .IX Header "Examples"
151 For examples of MRO implementations, see \f(CWS_mro_get_linear_isa_c3()\fR
152 and the \f(CW\*(C`BOOT:\*(C'\fR section of \fIext/mro/mro.xs\fR, and
153 \&\f(CWS_mro_get_linear_isa_dfs()\fR in \fImro_core.c\fR
154 .SH AUTHORS
155 .IX Header "AUTHORS"
156 The implementation of the C3 MRO and switchable MROs within the perl core was
157 written by Brandon L Black. Nicholas Clark created the pluggable interface,
158 refactored Brandon\*(Aqs implementation to work with it, and wrote this document.