MojoX::Loader - Loader of any Mojolicious Controller Modules in standalone script
# script.pl
use MojoX::Loader;
# Load App::User controller (App/User.pm) uses the base application module App (App.pm)
my $user = MojoX::Loader->load(controller => 'App::User');
# or
# Load MyApp::User controller (MyApp/User.pm) uses the base application module MyApp (MyApp.pm)
my $user = MojoX::Loader->load(app => 'MyApp', controller => 'MyApp::User');
# call the _total method from MyApp::User
say $user->_total;
MojoX::Loader is a module can load any Mojolicious Controller Modules in a standalone scripts (none Mojolicious scripts).
MojoX::Loader implements the following attributes.
my $app = $loader->app;
$app = $loader->app('MyApp');
Name of the base Mojolcious application, the default value is App.
my $c = $loader->controller;
$c = $loader->controller('MyApp::User');
Name of the Mojolicious Controller, the default value is Mojolicious::Controller.
my $log = $loader->log;
$app = $loader->log(Mojo::Log->new);
The logging layer of your application, by default a Mojo::Log object with debug level and STDERR handler.
my $prefix = $loader->prefix;
$prefix = $loader->prefix('../../');
The prefix for any path in application, for example renderer root.
MojoX::Loader inherits all methods from Mojo::Base and implements the following new ones.
my $user = MojoX::Loader->load(app => 'App', controller => 'App::User', prefix => '../../');
Load any Mojolicious Controller of application.
#!/usr/bin/env perl
use common::sense;
use lib qw(../.. ../../lib);
use MojoX::Loader;
my $user = MojoX::Loader->load(controller => 'App::User', prefix => '../../');
# call the method _total
say $user->_total;
<>;
# call the helper db
say $user->db;
<>;
# call the helper conf
say $user->conf('server')->{www};
<>;
# call the helper from App::Helpers
say $user->format_digital('1234567');
<>;
# render any template
say $user->render_partial('mail/test', format => 'mail');
Mojolicious Mojolicious::Guides http://mojolicio.us.
Anatoly Sharifulin <[email protected]>
Please report any bugs or feature requests to bug-mojox-loader at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.htMail?Queue=MojoX-Loader. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.
Github
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPANTS: CPAN Testing Service
CPAN Ratings
Search CPAN
Copyright (C) 2011 by Anatoly Sharifulin.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.