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