Frameworky Goodness: Mojolicious (Perl)

This topic was created by Frumious Bandersnatch .

  1. Frumious Bandersnatch Silver badge

    Frameworky Goodness: Mojolicious (Perl)

    I've spent the last couple of weeks playing around with this and learning more about it.

    The first line in the main manpage bills itself as "[a]n amazing real-time web framework...".

    The more I'm learning about it, the more I have to agree with the "amazing" bit. As a framework for building websites, it doesn't throw out loads of abstractions that you have to learn about first. It's MVC, but is agnostic on what Model implementation you use. Routing grafts actions into your site's URL space, and a stash (a simple hashref) is set up to keep track of everything from the point at which a request is dispatched from the router until something renders back a reply to the web user. Flexible in how these are implemented, ranging from callbacks in the routing setup to full MVC treatment with a simple but powerful templating engine (fully eval'd perl instead of a DDL/DSL) and controller classes.

    Extending the high-level framework is very easy thanks to its plugin, helper and command features. Plenty of really nice modern features like fluent interfaces (especially nice when writing test scripts), roles, perl attributes and method signatures, Moose-like "has", lazy perl state variables, a "Lite" mode, embedded user agent and web servers, hundreds of plugins, etc., etc.

    The most amazing thing, though, is that it seems to have all its turtles in a row, all the way down. I used to use POE for event-based programming, but the base Mojo class provides a similar set of features for async/non-blocking code without you having to think of things in the "POE" way (with wheels and whatever). Can also detect libev, automatically making your code more responsive.

    I'm barely scratching the surface of what the lower-level Mojo framework provides, but I've been benefiting from it every day that I code using Mojolicious. You get a high quality non-blocking web server and testing framework as well as async database access (Mojo::Pg) all without the slightest bit of fuss. The Mojo::Promise feature lets you write your own async code in a very synchronous style so future users (including future you) don't have to get bogged down with the nitty-gritty of how it works under the hood.

    Besides replacing POE for event-driven programming, the Mojo/Mojolicious frameworks are also a pretty good replacement for micro service deployment frameworks like Docker. Having no external dependencies and the ability to deploy a bunch of different Mojolicious applications via Mojolicious::Plugin::Mount completely eliminates the need for 3rd party middleware. Stick it into an LXC container or hide it behind an nginx reverse proxy if you wish, but it's not necessary. The embedded production web server (hypnotoad) has zero-downtime upgrades baked in as standard, so git-based push-to-deploy is a complete doddle.

    Also, the code is well written and very readable so it's as easy to consult as the copious manpages and guides that are included.

    If you're developing a web/websocket application and you speak Perl, then Mojolocious is the full-stack solution you've been looking for. No word of a lie.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019