Devel:...tubber(3perl)
β¨ NAME β¨
okay so bestie, meet Devel::SelfStubber (it's a 3perl kinda situation, from the Perl Programmers Reference Guide) β it generates stubs for a SelfLoading module π
β¨ SYNOPSIS β¨
if you just want the stubs and nothing else, it's giving:
use Devel::SelfStubber;
Devel::SelfStubber->stub('MODULENAME','MY_LIB_DIR');
or, if you want the whole entire module with the stubs slotted in correctly, do this:
use Devel::SelfStubber;
$Devel::SelfStubber::JUST_STUBS=0;
Devel::SelfStubber->stub('MODULENAME','MY_LIB_DIR');
okay important thing, no cap: MODULENAME is the Perl module name, like Devel::SelfStubber β NOT 'Devel/SelfStubber' and NOT 'Devel/SelfStubber.pm'. don't do that. that's not the vibe. π
and MY_LIB_DIR defaults to . if you don't hand it one. periodt. β¨
β¨ DESCRIPTION β¨
so what does it actually do? Devel::SelfStubber prints the stubs you need to put in the module before the __DATA__ token β or, if you're feeling extra, you can make it print the entire module with the stubs correctly placed. why do we care? because the stubs make sure that if a method gets called, it will get loaded. π«Ά
and like, specifically? they're needed for inherited autoloaded methods. that's the whole thing. that's the assignment.
the best way to explain this is with an example, so buckle up:
assume four classes: A, B, C & D.
A is the root class, B is a subclass of A, C is a subclass of B, and D is another subclass of A.
A
/ \
B D
/
C
okay now here's the plot π If D calls an autoloaded method 'foo' which is defined in class A, then the method is loaded into class A, then executed. fine, whatever. but then if C calls method 'foo', and that method was reimplemented in class B but set to be autoloaded... the lookup mechanism never gets to the AUTOLOAD mechanism in B, because it first finds the method already loaded in A, and so erroneously uses that. π it's giving wrong answer. it's giving bug.
but!! if the method foo had been stubbed in B, then the lookup mechanism would have found the stub, and correctly loaded and used the sub from B. slay. π
so: for classes and subclasses to have inheritance correctly work with autoloading, you need to ensure stubs are loaded. no stubs, no slay.
the SelfLoader can load stubs automatically at module initialization with the statement 'SelfLoader->load_stubs()'; β cute β but you may wish to avoid having the stub loading overhead associated with your initialization. (though ngl, note that the SelfLoader::load_stubs method will be called sooner or later β at latest when the first sub is being autoloaded.) in that case, you can put the sub stubs before the __DATA__ token. you could do this manually, but this module lets you automatically generate the stubs. main character energy honestly. π
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. π
and at the very least, this is useful to see what the SelfLoader thinks are stubs β because, 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. yes bestie, it checks its own work. iconic behaviour fr fr. β
π tiny reminder: MODULENAME is the Perl module name likeDevel::SelfStubber, not a path like'Devel/SelfStubber.pm'. and MY_LIB_DIR defaults to.. iykyk. π¦
and that's the whole page, bestie!! this one's perl v5.44.0 and it's dated 2026-10-17, from the Devel:...tubber(3perl) era π thanks for reading all the way to the bottom, you ate that. πβ¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms