Mojo::Loader(3)
β¨ NAME β¨
okay so bestie, this is the User Contributed Perl Documentation page for Mojo::Loader(3) β literally the class loader and plugin framework icon, and we're about to give it the full main-character treatment. π
πΈ SYNOPSIS πΈ
use Mojo::Loader qw(data_section find_modules load_class);
# Find modules in a namespace
for my $module (find_modules 'Some::Namespace') {
# Load them safely
my $e = load_class $module;
warn qq{Loading "$module" failed: $e} and next if ref $e;
# And extract files from the DATA section
say data_section($module, 'some_file.txt');
}
π¦ DESCRIPTION π¦
Mojo::Loader is a class loader and plugin framework. Aside from finding modules and loading classes, it lets multiple files be stored in the DATA section of a class, which can then be accessed individually. Obsessed, honestly.
package Foo;
1;
__DATA__
@@ test.txt
This is the first file.
@@ test2.html (base64)
VGhpcyBpcyB0aGUgc2Vjb25kIGZpbGUu
@@ test
This is the
third file.
Each file has a header starting with @@, followed by the file name and optional instructions for decoding its content. Currently only the Base64 encoding is supported, which can be quite convenient for the storage of binary data. slay for binary files, no cap. β¨
π FUNCTIONS π
Mojo::Loader implements the following functions, which can be imported individually.
π data_section
my $all = data_section 'Foo::Bar';
my $index = data_section 'Foo::Bar', 'index.html';
Extract an embedded file from the DATA section of a class. All files will be cached once they have been accessed for the first time. lowkey efficient.
# List embedded files
say for keys %{data_section 'Foo::Bar'};
π file_is_binary
my $bool = file_is_binary 'Foo::Bar', 'test.png';
Check if an embedded file from the DATA section of a class was Base64 encoded. cute little vibe check for binary-ness. π«Ά
π¦ find_packages
my @pkgs = find_packages 'MyApp::Namespace';
Search for packages in a namespace non-recursively. no deep-diving here, bestie.
π find_modules
my @modules = find_modules 'MyApp::Namespace';
my @modules = find_modules 'MyApp::Namespace', {recursive => 1};
Search for modules in a namespace.
These options are currently available:
recursiveβrecursive => 1; search the namespace recursively.
π load_class
my $e = load_class 'Foo::Bar';
Load a class and catch exceptions. Returns a false value if loading was successful, a true value if the class was not found, or a Mojo::Exception object if loading failed. Note that classes are checked for a new method to see if they are already loaded, so trying to load the same class multiple times may yield different results. iykyk.
# Handle exceptions
if (my $e = load_class 'Foo::Bar') {
die ref $e ? "Exception: $e" : 'Not found!';
}
π load_classes
my @classes = load_classes 'Foo::Bar';
Load all classes in a namespace recursively. periodt.
π«Ά SEE ALSO π«Ά
MojoliciousMojolicious::Guides<https://mojolicious.org>
byeee bestie, this was Mojo::Loader(3) β source/version perl v5.42.0, dated 2026-07-15 π¦πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms