Method::Autoload(3pm)

πŸ“¦
version 0.02 Β· 3 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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 πŸ’œ


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