Method::Autoload(3pm)
π Method::Autoload π
okay bestie, so this is Method::Autoload β a lil User Contributed Perl Documentation page, and it's literally the friend that goes "don't worry, I gotchu" when you have no idea what methods exist until the program is actually running. It autoloads methods from a list of packages straight into the current package. slay.
β¨ NAME β¨
Method::Autoload β autoloads methods from a list of packages into the current package. that's the whole vibe, no cap π¦
β¨ SYNOPSIS β¨
package MyPackage;
use base qw{Method::Autoload}
that's it. that's the setup. one use base line and you're in business π
β¨ DESCRIPTION β¨
So the Method::Autoload base class package exists to autoload methods from a list of packages β and the whole point is that you might not know what methods are even available until run time. It's giving mystery, it's giving chaos, it's giving "we'll find out together." π
A genuinely great use of this package? programming support for user contributed packages or user contributed plugins. Like, your users drop in their own stuff, and you're not out here trying to predict the future. iconic behavior honestly.
β¨ USAGE β¨
use MyPackage;
my $object=MyPackage->new(%hash); #provides new and initialize methods
$object->pushPackages("My::Bar"); #appends to "packages" array
$object->unshiftPackages("My::Foo"); #prepends to "packages" array
use MyPackage;
my $object=MyPackage->new(packages=>["My::Foo", "My::Bar"]);
$object->foo; #from My::Foo
$object->bar; #from My::Bar
okay so see how new is already handing you new and initialize? cute. and then you're just stacking packages onto the "packages" array β appending them, prepending them, whatever your heart says. then you call $object->foo and $object->bar and they just... show up. from My::Foo and My::Bar. it's giving magic but it's just autoloading πͺβ¨
β¨ CONSTRUCTOR β¨
π new
my $object=MyPackage->new(%hash);
my $object=MyPackage->new(package=>["My::Package1", "My::Package2"]);
(and yes bestie, that second one is literally how the original writes it β package=>, singular, no "s". copy it exactly, i don't make the rules π)
π initialize
no arguments listed, no code sample, just vibes. it's there, it's part of the constructor story, and it comes free with new. periodt.
β¨ METHODS PUBLIC β¨
πΈ packages
Returns the current list of packages in the "packages" array. give it list context, get the list; give it scalar context, get the arrayref. π
my @package=$object->packages; #()
my $package=$object->packages; #[]
πΈ pushPackages
Pushes packages on to the "packages" array. one at a time, or a whole squad at once π
$object->pushPackages("My::Bar");
$object->pushPackages(@packages);
πΈ unshiftPackages
Unshifts packages on to the "packages" array. Use this if you want to override a "default" package.
β οΈ Please use with care. like, genuinely. this one goes in at the FRONT, so it's stepping ahead of everything already in line. respect the queue, bestie π
$object->unshiftPackages("My::Foo");
$object->unshiftPackages(@packages);
πΈ autoloaded
Returns a hash of autoloaded methods and the classes that they came from. so you can finally see who came from where β a little receipts moment π§Ύβ¨
my %hash=$object->autoloaded; #()
my $hash=$object->autoloaded; #{}
β¨ METHODS PRIVATE β¨
π DESTROY ("Global" method)
We define DESTROY in this package so that it does not call AUTOLOAD β but you may overload this method in your package, if you need it. so it's a deliberate little guardrail, and you're free to do your own thing on top of it π
π AUTOLOAD ("Global" method)
AUTOLOAD is a "global" method. Please review the limitations on inheriting this method.
π«Ά real talk: this one's a global, so inheritance gets weird. go read up on the limitations before you go inheriting it all willy-nilly, fr fr.
π autoload
my $subref=$object->autoload($class, $method);
hands you back a subref. that's the whole thing. short, sweet, private π₯
π BUGS π
DavisNetworks.com provides support services for all Perl applications including this package. (yes, that's the entire bugs section. no bug list, just "call these people." honestly? iconic.)
π«Ά SUPPORT π«Ά
(that's literally all the original says here β the section exists, and it is vibes only. the actual support info lives in BUGS and AUTHOR, so scroll accordingly πΈ)
π AUTHOR π
Michael R. Davis
CPAN ID: MRDVT
STOP, LLC
domain=>michaelrdavis,tld=>com,account=>perl
http://www.stopllc.com/
shoutout to Michael R. Davis, CPAN ID MRDVT, of STOP, LLC β contact deets written as a hash, which is honestly such a Perl move and i love that for him π
π COPYRIGHT π
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module. go read it, it's right there in the box π
π SEE ALSO π
Class::Std AUTOMETHOD method,
(that's it β that's the whole line, trailing comma and all. we keep it exactly as it is, no editing, no tidying, periodt β¨)
and that's the whole page, bestie!! this was Method::Autoload(3pm) from the User Contributed Perl Documentation, shipped as part of perl v5.32.0 and dated 2021-01-04. go forth, autoload responsibly, and remember: unshift with care ππ¦πΈπ
π
π¦ where this page comes from
- debian bookworm: libmethod-autoload-perl 0.02-2.1 Β· BSD-3-Clause~STOP
- ubuntu jammy: libmethod-autoload-perl 0.02-2.1 Β· BSD-3-Clause~STOP
- ubuntu noble: libmethod-autoload-perl 0.02-2.1 Β· BSD-3-Clause~STOP
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms