Mojolicious is a lightweight web framework inspired by Ruby frameworks. It uses PSGI and includes features like ORM, templating, internationalization, and forms. Some key differences between Mojolicious and Dancer are that in Mojolicious the application is defined as a class rather than a script, the code is more "natural" with no magic, and Mojolicious routes are very powerful. What works well about Mojolicious is the good documentation, fast IRC support, powerful routing system, extensive test suite, and clear no dependencies policy. However, the no dependencies policy can cause issues, some tests may not be relevant, and the Template Toolkit renderer requires prefixing all variables with "c.".
3. What is Mojolicious?
• Web framework
• “New wave” of light-weight Ruby-inspired f.
• WSGI -> PSGI
• Includes Plack, Dancer, Mojolicious, ...
4. How to define a framework?
• Request lifecycle
• Features? ORM, Templating, I18N,
Forms, Layout, ...
• Testing?
• Deployment: deps? Stand-alone servers?
(starman, hypnotoad, ...)
• Documentation?
• ... what else?
5. Let's look at Dancer
• Excellent documentation
https://metacpan.org/module/Dancer::Introduction
• DSL and script oriented
use Dancer;
get '/login' => sub {
# do something
};
any ['get', 'post'] => '/login/verify' => sub {
# do something
}
6. Let's look at Dancer / 2
Too much DSL oriented?
before sub {
if (!session('user') && request->path_info !~
m{^/login}) {
# Pass the original path along to the handler:
var requested_path => request->path_info;
request->path_info('/login');
}
};
7. Compare with Mojolicious
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->hook(before_dispatch => sub {
my $c = shift;
if(!$c->session('user') && $c->stash('action')!~/^login/) {
$c->stash('action') = 'login';
}
});
}
... except whole example would be pointless in
Mojolicious because of named routes
8. Compare with Mojolicious
use base 'Mojolicious';
sub startup {
my $self = shift;
$self->sessions->cookie_name('auth_session');
$self->sessions->default_expiration(7200);
$self->plugin('I18N' => (namespace => 'Auth::Locale'));
$self->renderer->default_handler('tt');
my $r = $self->routes;
$r->route('/login')->to('login#index');
$r->route('/login/verify')->to('login#verify');
$self->hook(before_dispatch => sub { do($something) });
}
9. Differences, Mojo vs Dancer
• Application is a class, not a script
• Code is “natural”. No magic. Obvious.
• Mojo Routes are awesome. Really.
• Hooks are similar, but PLA/POLS rules
• ... what else?
10. What works?
• Good docs. Need more meaningful examples.
• Fast feedback on IRC #mojo (irc.perl.org)
• Routes! Best of Perl and non-Perl frameworks
• Extensive test suite
• Clear no deps policy
11. What doesn't work?
or rather, the most annoying problems I found
• No deps policy
(cookie parsing)
• Tons of tests, but are they relevant?
(cookie parsing and generations tests again)
• Template Toolkit renderer
(c.* prefix)