2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>Devel::SelfStubber - generate stubs for a SelfLoading module
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> Devel::SelfStubber - generate stubs for a SelfLoading module
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
31 <h1><a name=
"name">NAME
</a></h1>
32 <p>Devel::SelfStubber - generate stubs for a SelfLoading module
</p>
36 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
37 <p>To generate just the stubs:
</p>
39 use Devel::SelfStubber;
40 Devel::SelfStubber-
>stub('MODULENAME','MY_LIB_DIR');
</pre>
41 <p>or to generate the whole module with stubs inserted correctly
</p>
43 use Devel::SelfStubber;
44 $Devel::SelfStubber::JUST_STUBS=
0;
45 Devel::SelfStubber-
>stub('MODULENAME','MY_LIB_DIR');
</pre>
46 <p>MODULENAME is the Perl module name, e.g. Devel::SelfStubber,
47 NOT 'Devel/SelfStubber' or 'Devel/SelfStubber.pm'.
</p>
48 <p>MY_LIB_DIR defaults to '.' if not present.
</p>
52 <h1><a name=
"description">DESCRIPTION
</a></h1>
53 <p>Devel::SelfStubber prints the stubs you need to put in the module
54 before the __DATA__ token (or you can get it to print the entire
55 module with stubs correctly placed). The stubs ensure that if
56 a method is called, it will get loaded. They are needed specifically
57 for inherited autoloaded methods.
</p>
58 <p>This is best explained using the following example:
</p>
59 <p>Assume four classes, A,B,C
& D.
</p>
60 <p>A is the root class, B is a subclass of A, C is a subclass of B,
61 and D is another subclass of A.
</p>
68 <p>If D calls an autoloaded method 'foo' which is defined in class A,
69 then the method is loaded into class A, then executed. If C then
70 calls method 'foo', and that method was reimplemented in class
71 B, but set to be autoloaded, then the lookup mechanism never gets to
72 the AUTOLOAD mechanism in B because it first finds the method
73 already loaded in A, and so erroneously uses that. If the method
74 foo had been stubbed in B, then the lookup mechanism would have
75 found the stub, and correctly loaded and used the sub from B.
</p>
76 <p>So, for classes and subclasses to have inheritance correctly
77 work with autoloading, you need to ensure stubs are loaded.
</p>
78 <p>The SelfLoader can load stubs automatically at module initialization
79 with the statement 'SelfLoader-
>load_stubs()';, but you may wish to
80 avoid having the stub loading overhead associated with your
81 initialization (though note that the SelfLoader::load_stubs method
82 will be called sooner or later - at latest when the first sub
83 is being autoloaded). In this case, you can put the sub stubs
84 before the __DATA__ token. This can be done manually, but this
85 module allows automatic generation of the stubs.
</p>
86 <p>By default it just prints the stubs, but you can set the
87 global $Devel::SelfStubber::JUST_STUBS to
0 and it will
88 print out the entire module with the stubs positioned correctly.
</p>
89 <p>At the very least, this is useful to see what the SelfLoader
90 thinks are stubs - in order to ensure future versions of the
91 SelfStubber remain in step with the SelfLoader, the
92 SelfStubber actually uses the SelfLoader to determine which
94 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
95 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
96 <big><strong><span class=
"block"> Devel::SelfStubber - generate stubs for a SelfLoading module
</span></strong></big>