Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Devel::SelfStubber.3pm

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 "Devel::SelfStubber 3pm"
61 .TH Devel::SelfStubber 3pm 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 Devel::SelfStubber \- generate stubs for a SelfLoading module
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 To generate just the stubs:
71 .PP
72 .Vb 2
73 \& use Devel::SelfStubber;
74 \& Devel::SelfStubber\->stub(\*(AqMODULENAME\*(Aq,\*(AqMY_LIB_DIR\*(Aq);
75 .Ve
76 .PP
77 or to generate the whole module with stubs inserted correctly
78 .PP
79 .Vb 3
80 \& use Devel::SelfStubber;
81 \& $Devel::SelfStubber::JUST_STUBS=0;
82 \& Devel::SelfStubber\->stub(\*(AqMODULENAME\*(Aq,\*(AqMY_LIB_DIR\*(Aq);
83 .Ve
84 .PP
85 MODULENAME is the Perl module name, e.g. Devel::SelfStubber,
86 NOT \*(AqDevel/SelfStubber\*(Aq or \*(AqDevel/SelfStubber.pm\*(Aq.
87 .PP
88 MY_LIB_DIR defaults to \*(Aq.\*(Aq if not present.
89 .SH DESCRIPTION
90 .IX Header "DESCRIPTION"
91 Devel::SelfStubber prints the stubs you need to put in the module
92 before the _\|_DATA_\|_ token (or you can get it to print the entire
93 module with stubs correctly placed). The stubs ensure that if
94 a method is called, it will get loaded. They are needed specifically
95 for inherited autoloaded methods.
96 .PP
97 This is best explained using the following example:
98 .PP
99 Assume four classes, A,B,C & D.
100 .PP
101 A is the root class, B is a subclass of A, C is a subclass of B,
102 and D is another subclass of A.
103 .PP
104 .Vb 5
105 \& A
106 \& / \e
107 \& B D
108 \& /
109 \& C
110 .Ve
111 .PP
112 If D calls an autoloaded method \*(Aqfoo\*(Aq which is defined in class A,
113 then the method is loaded into class A, then executed. If C then
114 calls method \*(Aqfoo\*(Aq, and that method was reimplemented in class
115 B, but set to be autoloaded, then the lookup mechanism never gets to
116 the AUTOLOAD mechanism in B because it first finds the method
117 already loaded in A, and so erroneously uses that. If the method
118 foo had been stubbed in B, then the lookup mechanism would have
119 found the stub, and correctly loaded and used the sub from B.
120 .PP
121 So, for classes and subclasses to have inheritance correctly
122 work with autoloading, you need to ensure stubs are loaded.
123 .PP
124 The SelfLoader can load stubs automatically at module initialization
125 with the statement \*(AqSelfLoader\->\fBload_stubs()\fR\*(Aq;, but you may wish to
126 avoid having the stub loading overhead associated with your
127 initialization (though note that the SelfLoader::load_stubs method
128 will be called sooner or later \- at latest when the first sub
129 is being autoloaded). In this case, you can put the sub stubs
130 before the _\|_DATA_\|_ token. This can be done manually, but this
131 module allows automatic generation of the stubs.
132 .PP
133 By default it just prints the stubs, but you can set the
134 global \f(CW$Devel::SelfStubber::JUST_STUBS\fR to 0 and it will
135 print out the entire module with the stubs positioned correctly.
136 .PP
137 At the very least, this is useful to see what the SelfLoader
138 thinks are stubs \- in order to ensure future versions of the
139 SelfStubber remain in step with the SelfLoader, the
140 SelfStubber actually uses the SelfLoader to determine which
141 stubs are needed.