1Devel::SelfStubber(3pm)Perl Programmers Reference GuideDevel::SelfStubber(3pm)
2
3
4

NAME

6       Devel::SelfStubber - generate stubs for a SelfLoading module
7

SYNOPSIS

9       To generate just the stubs:
10
11           use Devel::SelfStubber;
12           Devel::SelfStubber->stub('MODULENAME','MY_LIB_DIR');
13
14       or to generate the whole module with stubs inserted correctly
15
16           use Devel::SelfStubber;
17           $Devel::SelfStubber::JUST_STUBS=0;
18           Devel::SelfStubber->stub('MODULENAME','MY_LIB_DIR');
19
20       MODULENAME is the Perl module name, e.g. Devel::SelfStubber, NOT
21       'Devel/SelfStubber' or 'Devel/SelfStubber.pm'.
22
23       MY_LIB_DIR defaults to '.' if not present.
24

DESCRIPTION

26       Devel::SelfStubber prints the stubs you need to put in the module
27       before the __DATA__ token (or you can get it to print the entire module
28       with stubs correctly placed). The stubs ensure that if a method is
29       called, it will get loaded. They are needed specifically for inherited
30       autoloaded methods.
31
32       This is best explained using the following example:
33
34       Assume four classes, A,B,C & D.
35
36       A is the root class, B is a subclass of A, C is a subclass of B, and D
37       is another subclass of A.
38
39                               A
40                              / \
41                             B   D
42                            /
43                           C
44
45       If D calls an autoloaded method 'foo' which is defined in class A, then
46       the method is loaded into class A, then executed. If C then calls
47       method 'foo', and that method was reimplemented in class B, but set to
48       be autoloaded, then the lookup mechanism never gets to the AUTOLOAD
49       mechanism in B because it first finds the method already loaded in A,
50       and so erroneously uses that. If the method foo had been stubbed in B,
51       then the lookup mechanism would have found the stub, and correctly
52       loaded and used the sub from B.
53
54       So, for classes and subclasses to have inheritance correctly work with
55       autoloading, you need to ensure stubs are loaded.
56
57       The SelfLoader can load stubs automatically at module initialization
58       with the statement 'SelfLoader->load_stubs()';, but you may wish to
59       avoid having the stub loading overhead associated with your
60       initialization (though note that the SelfLoader::load_stubs method will
61       be called sooner or later - at latest when the first sub is being
62       autoloaded). In this case, you can put the sub stubs before the
63       __DATA__ token. This can be done manually, but this module allows
64       automatic generation of the stubs.
65
66       By default it just prints the stubs, but you can set the global
67       $Devel::SelfStubber::JUST_STUBS to 0 and it will print out the entire
68       module with the stubs positioned correctly.
69
70       At the very least, this is useful to see what the SelfLoader thinks are
71       stubs - in order to ensure future versions of the SelfStubber remain in
72       step with the SelfLoader, the SelfStubber actually uses the SelfLoader
73       to determine which stubs are needed.
74
75
76
77perl v5.28.2                      2018-11-01           Devel::SelfStubber(3pm)
Impressum