<?xml version="1.0" encoding="windows-1252"?>
<node id="1177" title="perlman:Devel::SelfStubber" created="1999-12-22 19:51:30" updated="2005-08-10 16:18:48">
<type id="119">
perlfunc</type>
<author id="113">
root</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
Devel::SelfStubber - generate stubs for a SelfLoading module

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
To generate just the stubs:

&lt;P&gt;
&lt;PRE&gt;    use Devel::SelfStubber;
    Devel::SelfStubber-&amp;gt;stub('MODULENAME','MY_LIB_DIR');
&lt;/PRE&gt;
&lt;P&gt;
or to generate the whole module with stubs inserted correctly

&lt;P&gt;
&lt;PRE&gt;    use Devel::SelfStubber;
    $Devel::S</field>
<field name="description">

&lt;P&gt;
Devel::SelfStubber prints the stubs you need to put in the module before the 
&lt;FONT SIZE=-1&gt;__DATA__&lt;/FONT&gt; token (or you can get it to print the entire module with stubs correctly placed). The stubs ensure that if a method is called, it will get loaded. They are needed specifically for inherited autoloaded methods.

&lt;P&gt;
This is best explained using the following example:

&lt;P&gt;
Assume four classes, 
&lt;FONT SIZE=-1&gt;A,B,C&lt;/FONT&gt; &amp;amp; 
&lt;FONT SIZE=-1&gt;D.&lt;/FONT&gt;

&lt;P&gt;

&lt;FONT SIZE=-1&gt;A&lt;/FONT&gt; is the root class, 
&lt;FONT SIZE=-1&gt;B&lt;/FONT&gt; is a subclass of 
&lt;FONT SIZE=-1&gt;A,&lt;/FONT&gt; 
&lt;FONT SIZE=-1&gt;C&lt;/FONT&gt; is a subclass of 
&lt;FONT SIZE=-1&gt;B,&lt;/FONT&gt; and 
&lt;FONT SIZE=-1&gt;D&lt;/FONT&gt; is another subclass of 
&lt;FONT SIZE=-1&gt;A.&lt;/FONT&gt;

&lt;P&gt;
&lt;PRE&gt;                        A
                       / \
                      B   D
                     /
                    C
&lt;/PRE&gt;
&lt;P&gt;
If 
&lt;FONT SIZE=-1&gt;D&lt;/FONT&gt; calls an autoloaded method 'foo' which is defined in class 
&lt;FONT SIZE=-1&gt;A,&lt;/FONT&gt; then the method is loaded into class 
&lt;FONT SIZE=-1&gt;A,&lt;/FONT&gt; then executed. If 
&lt;FONT SIZE=-1&gt;C&lt;/FONT&gt; then calls method 'foo', and that method was reimplemented in class 
&lt;FONT SIZE=-1&gt;B,&lt;/FONT&gt; but set to be autoloaded, then the lookup mechanism never gets to the 
&lt;FONT SIZE=-1&gt;AUTOLOAD&lt;/FONT&gt; mechanism in 
&lt;FONT SIZE=-1&gt;B&lt;/FONT&gt; because it first finds the method already loaded in 
&lt;FONT SIZE=-1&gt;A,&lt;/FONT&gt; and so erroneously uses that. If the method foo had been stubbed in 
&lt;FONT SIZE=-1&gt;B,&lt;/FONT&gt; then the lookup mechanism would have found the stub, and correctly loaded and used the sub from 
&lt;FONT SIZE=-1&gt;B.&lt;/FONT&gt;

&lt;P&gt;
So, for classes and subclasses to have inheritance correctly work with
autoloading, you need to ensure stubs are loaded.

&lt;P&gt;
The SelfLoader can load stubs automatically at module initialization with the statement 'SelfLoader-&amp;gt;load_stubs()';, but you may wish to avoid having the stub loading overhead associated with your initialization (though note that the SelfLoader::load_stubs method will be called sooner or later - at latest when the first sub is being autoloaded). In this case, you can put the sub stubs before the 
&lt;FONT SIZE=-1&gt;__DATA__&lt;/FONT&gt; token. This can be done manually, but this module allows automatic generation of the stubs.

&lt;P&gt;
By default it just prints the stubs, but you can set the global
$Devel::SelfStubber::JUST_STUBS to 0 and it will print out the entire
module with the stubs positioned correctly.

&lt;P&gt;
At the very least, this is useful to see what the SelfLoader thinks are
stubs - in order to ensure future versions of the SelfStubber remain in
step with the SelfLoader, the SelfStubber actually uses the SelfLoader to
determine which stubs are needed.

&lt;HR&gt;
</field>
</data>
</node>
