Dancer...Loader(3pm)
π NAME π
Dancer::ModuleLoader β dynamic module loading helpers for Dancer core components π
This page is Dancer...Loader(3pm), from the User Contributed Perl Documentation corner of the world, and bestie, it's here to teach you how to load modules whenever you feel like it instead of at compile time. Slay. β¨
πΈ VERSION πΈ
version 1.3522</purl> β okay ignore that typo, it's version 1.3522. Periodt.
β¨ SYNOPSIS β¨
Straight-up borrowed from Dancer::Template::TemplateToolkit (which is core, iykyk):
die "Template is needed by Dancer::Template::TemplateToolkit"
unless Dancer::ModuleLoader->load('Template');
# we now have Template loaded
Look at that. Chef's kiss. π
π¦ DESCRIPTION π¦
So here's the situation, bestie: sometimes in Dancer core we gotta use modules, but we do not wanna declare them all up front at compile-time. Why? Well, maybe those specific modules bring extra features, and those features depend on code that isn't β and honestly shouldn't be β in core. Or maybe we just want these components loaded in lazy style, saving a lil loading time. π
Like, why load Template (which Dancer doesn't even require!) when you literally never use Dancer::Template::TemplateToolkit? It's giving unnecessary.
Doing this whole thing properly takes a bit of code for localizing $@ and eval-ing. That code? Refactored into this very module, to help Dancer core developers out. π«Ά
β οΈ Please only use this for Dancer core modules. If you're writing an external Dancer module (Dancer::Template::Tiny,Dancer::Session::Cookie, etc.), justuse ModuleYouNeedin your code and leave this module alone. No cap. π
π METHODS/SUBROUTINES π
π« load
Runs something like use ModuleYouNeed β but at runtime. Main character behavior, honestly.
use Dancer::ModuleLoader;
...
Dancer::ModuleLoader->load('Something')
or die "Couldn't load Something\n";
# load version 5.0 or more
Dancer::ModuleLoader->load('Something', '5.0')
or die "Couldn't load Something\n";
# load version 5.0 or more
my ($res, $error) = Dancer::ModuleLoader->load('Something', '5.0');
$res or die "Couldn't load Something : '$error'\n";
Takes in arguments the module name, and optionally the minimum version number required. β
In scalar context, returns 1 if successful, 0 if not. In list context, returns 1 if successful, (0, "error message") if not.
π‘ Need to hand an argument to the loading module? Bestie, use the method load_with_params instead.
π require
Runs a require ModuleYouNeed. Simple as that.
use Dancer::ModuleLoader;
...
Dancer::ModuleLoader->require('Something')
or die "Couldn't require Something\n";
my ($res, $error) = Dancer::ModuleLoader->require('Something');
$res or die "Couldn't require Something : '$error'\n";
If you're unsure what you need (require or load), go learn the differences between require and use. Genuinely, it'll change your life. π
Takes in arguments the module name.
In scalar context, returns 1 if successful, 0 if not. In list context, returns 1 if successful, (0, "error message") if not.
πΈ load_with_params
Runs a use ModuleYouNeed qw(param1 param2 ...). Now with flavor. π
use Dancer::ModuleLoader;
...
Dancer::ModuleLoader->load_with_params('Something', qw(param1 param2) )
or die "Couldn't load Something with param1 and param2\n";
my ($res, $error) = Dancer::ModuleLoader->load_with_params('Something', @params);
$res or die "Couldn't load Something with @params: '$error'\n";
Takes in arguments the module name, and optionally parameters to pass to the import internal method.
In scalar context, returns 1 if successful, 0 if not. In list context, returns 1 if successful, (0, "error message") if not.
π use_lib
Runs a use lib qw(path1 path2) at run time instead of compile time. Dynamic queen. π
use Dancer::ModuleLoader;
...
Dancer::ModuleLoader->use_lib('path1', @other_paths)
or die "Couldn't perform use lib\n";
my ($res, $error) = Dancer::ModuleLoader->use_lib('path1', @other_paths);
$res or die "Couldn't perform use lib : '$error'\n";
Takes in arguments a list of path to be prepended to @INC, in a similar way than use lib. However, this is performed at run time, so the list of paths can be generated and dynamic. That's the whole point, bestie. π
In scalar context, returns 1 if successful, 0 if not. In list context, returns 1 if successful, (0, "error message") if not.
π§ class_from_setting
Given a setting in Dancer::Config, composes the class it should be. It's giving translator. π₯
This is the function that translates:
# in config.yaml
template: "template_toolkit"
To the class:
Dancer::Template::TemplateToolkit
Example:
use Dancer::ModuleLoader;
my $class = Dancer::ModuleLoader->class_from_setting(
'Dancer::Template' => 'template_toolkit',
);
# $class == 'Dancer::Template::TemplateToolkit
$class = Dancer::ModuleLoader->class_from_setting(
'Dancer::Template' => 'tiny',
);
# class == 'Dancer::Template::Tiny
(Yes, those trailing quotes in the comments are exactly like that in the original. We're not fixing it, we're respecting it. π)
π₯ SEE ALSO π₯
Module::LoadModule::New::Loader
π AUTHOR π
Dancer Core Developers π«Ά
β COPYRIGHT AND LICENSE β
This software is copyright (c) 2010 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.40.1 Β· 2026-05-05 Β· and that's the whole Dancer...Loader(3pm) page, bestie β go load some modules dynamically, you absolute icon. β¨π
π¦ where this page comes from
- ubuntu stonking: libdancer-perl 1.3522-2 Β· Artistic-1.0-Perl OR 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