Module::Loader(3)
β¨ NAME β¨
okay bestie, welcome to the Module::Loader(3) page from the User Contributed Perl Documentation π. This module is literally about finding and loading modules in a given namespace β thatβs the whole vibe check. Periodt.
π¦ SYNOPSIS π¦
use Module::Loader;
my $loader = Module::Loader->new;
my @plugins = $loader->find_modules('MyApp::Plugin');
foreach my $plugin (@plugins) {
$loader->load($plugin);
}
πΈ DESCRIPTION πΈ
okay so hereβs the tea π: this module gives you methods for finding modules in a given namespace and then loading them. Itβs intended for situations where youβre looking for plugins and then loading one or more of them. Iconic, honestly.
This module was inspired by Mojo::Loader, which the author used in a number of projects. But some people were wary of requiring Mojolicious just to get a module loader, which prompted the author to create Module::Loader. No cap.
Note: this module was initially calledPlugin::Loader, but the author realised thatModule::Loaderwas a more appropriate name. iykyk π
π new π
When instantiating Module::Loader, you can optionally set the max_depth attribute, which limits the search depth when looking for modules.
my $loader = Module::Loader->new(max_depth => 1);
Letβs say you have all of the CPAN plugins for the template toolkit installed locally. If you donβt specify max_depth, then find_modules('Template::Plugin') would return Template::Plugin::Filter::Minify::JavaScript as well as Template::Plugin::File. If you set max_depth to 1, then youβd get the latter but not the former. Slay.
Why might you want to do that? Great question, bestie π«Ά. You might have a convention where plugins are the modules immediately within the specified namespace, but that each plugin can have additional modules within its own namespace. Thatβs the whole point.
So typically youβll either not set max_depth, or youβll set it to 1. Thatβs it. Thatβs the vibe.
π METHODS π
π find_modules π
Takes a namespace, and returns all installed modules in that namespace, that were found in @INC. For example:
@plugins = $loader->find_modules('Template::Plugin');
By default this will find all modules in the given namespace, unless youβve specified a maximum search depth, as described above. You can also specify max_depth when you call the method:
@plugins = $loader->find_modules('Template::Plugin',
{ max_depth => 1 });
π₯ search π₯
This is the same as find_modules() above, but it hard-codes the search depth to 1. This method is provided for compatibility with Mojo::Loader:
@plugins = $loader->search('Template::Plugin');
It just calls find_modules() with max_depth set to 1, as shown above. No extra lore, itβs literally that.
π load π
Takes a module name and tries to load the module.
$loader->load('MyModule::Plugin::Spank');
If loading fails, then we croak. Thatβs the important part, bestie π.
π max_depth π
Returns the value of the max_depth, if it was passed to the constructor, otherwise undef.
π¦ SEE ALSO π¦
Mojo::Loaderwas the inspiration for this module, but has a slightly different interface. In particular, it hasmax_depthhard-coded to 1.Module::Pluggableis effectively a role which gives a class the ability to find plugins within its namespace.Module::Pluggable::Orderedis similar toModule::Pluggable, but lets you control the order in which modules are loaded.allwill load all modules in a given namespace, eg withuse all 'IO::*';lib::require::allwill load all modules found in a given directory (as opposed to a namespace).MAD::Loaderprovides functions for loading modules, but not for finding them.Module::Findprovides a number of functions for finding and loading modules. It provides different functions depending on whether you want to limit the search depth to 1 or not:findallmodvsfindsubmod.Module::Recursive::Requirewill load all modules in a given namespace, and return a list of the modules found / loaded. It lets you provide regexps for filtering out certain namespaces.Module::Requireprovides two functions,require_regexandrequire_globwhich will load all locally installed modules whose name matches a pattern (specified as a regular expression or glob-style pattern).
π REPOSITORY π
<https://github.com/neilbowers/Module-Loader> β go look, bestie β¨
πΈ AUTHOR πΈ
Neil Bowers <neilb@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2014 by Neil Bowers <neilb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay thatβs the whole page, bestie π
β source/version: perl v5.42.2; date: 2023-07-03; page: Module::Loader(3). periodt π«Ά
π¦ where this page comes from
- alpine 3.24: perl-module-loader-doc 0.04-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms