February 8, 2012

Mojolicious Full and Lite apps - understanding the difference

The mojocasts have thus far used lite apps exclusively to demonstrate basic Mojolicious functionality. This has led some to believe that Mojolicious is a one-file micro-framework; however, that is not the case.

Mojolicious a full-featured framework, supporting what some would call Catalyst-level deployments, in addition to one-file simple applications.

Mojolicious::Lite is a thin layer on top of the full framework - literally a 68-line module that provides Sinatra-like syntax, including the ability to embed base64-encoded binary files.

Full apps are a good choice for teams, and for sanely separating concerns for large web apps.

I've uploaded a sample application to demonstrate the differences, and allow folks to see first hand how to translate from Full to Lite, and vice-versa.

The example application demonstrates DBIx::Class integration, how to test your web app with Test::Mojo, as well as how to use EP templates with and without tag helpers. For those unfamiliar with testing in general, there are even examples of DBIC schema tests.

Both apps are identical in functionality: Full app Lite app

They are runnable using the morbo development server, as well as hypnotoad, the "full featured UNIX optimized preforking non-blocking I/O HTTP 1.1 and WebSocket server built around the very well tested and reliable Mojo::Server::Daemon with IPv6, TLS, Bonjour, libev and hot deployment support that just works".

Shnikies that's a lot of buzzwords for a Perl framework!

And as always, Mojolicious downloads and installs in about a minute:

curl -L cpanmin.us | perl - Mojolicious

Even better, enable parallel tests and you can install in about 15 seconds!

HARNESS_OPTIONS=j9 cpanm Mojolicious

Or skip tests entirely for a 4-second installation:

curl -L get.mojolicio.us | sh

\o/

comments powered by Disqus