NAME

Mojo::Loader - Universal Class Loader

SYNOPSIS

use Mojo::Loader;

# Long
my @instances = Mojo::Loader->new
  ->namespace('Some::Namespace')
  ->search
  ->load
  ->base('Some::Module')
  ->instantiate;

# Short
my @instances = Mojo::Loader->new->mods('Some::Namespace')->inst;

# Reload
Mojo::Loader->reload;

DESCRIPTION

Mojo::Loader is a universal class loader and plugin framework.

ATTRIBUTES

base

my $base = $loader->base;
$loader  = $loader->base('MyApp::Base');

modules

my @modules = $loader->mods;
$loader     = $loader->mods(qw/MyApp::Foo MyApp::Bar/);
my @modules = $loader->modules;
$loader     = $loader->modules(qw/MyApp::Foo MyApp::Bar/);

namespace

my $namespace = $loader->namespace;
$loader       = $loader->namespace('MyApp::Namespace');

METHODS

Mojo::Loader inherits all methods from Mojo::Base and implements the following new ones.

new

my $loader = Mojo::Loader->new;
my $loader = Mojo::Loader->new('MyApp::Namespace');

instantiate

my $first     = $loader->inst;
my @instances = $loader->inst;
my $first     = $loader->inst(qw/foo bar baz/);
my @instances = $loader->inst(qw/foo bar baz/);
my $first     = $loader->instantiate;
my @instances = $loader->instantiate;
my $first     = $loader->instantiate(qw/foo bar baz/);
my @instances = $loader->instantiate(qw/foo bar baz/);

Note that only the main package will be instantiated, file contents won't be scanned for multiple package declarations.

load

$loader = $loader->load;
$loader = $loader->search;
$loader = $loader->search('MyApp::Namespace');

reload

Mojo::Loader->reload;