Perl releases a "real time web framework" - Mojolicious 8.0

I don’t really see anything that jumps out at me from living in Phoenix land, but it might be interesting to see what people seem to like about it. I’m not used to seeing Perl stuff make the HN frontpage so it got my attention.


I quite like the name :lol:

But other than that, I think the syntax would drive me a bit crazy - all those curly braces :101:

use Mojolicious::Lite -signatures;

# Render template "index.html.ep" from the DATA section
get '/' => sub ($c) {
  $c->render(template => 'index');

# WebSocket service used by the template to extract the title from a web site
websocket '/title' => sub ($c) {
  $c->on(message => sub ($c, $msg) {
    my $title = $c->ua->get($msg)->result->dom->at('title')->text;


@@ index.html.ep
% my $url = url_for 'title';
  var ws = new WebSocket('<%= $url->to_abs %>');
  ws.onmessage = function (event) { document.body.innerHTML += };
  ws.onopen    = function (event) { ws.send('') };
1 Like

Oh you haven’t even learned the true horror of Perl, context! ^.^

The ‘context’ in which you pass a variable and the ‘context’ in which it is consumed can completely change how a variable works, from something as simple as a list in a list context returning a list or a list in a scaler context returning the length, any function can access any of it’s arguments in any context it wants even if based on the time of day if it wants, and the context matters in how you are able to store it as even the variable bindings themselves have a context! (Edit: A function can even know in what context it’s being called in an can choose to do entirely different things too!)

It gives you a lot of power, but it definitely made for a lot of the heck just happened here?! moments over the years. ^.^;

Honestly the context mess is not quite as bad now as it was back in my day’s version of perl, but it’s still there. :slight_smile:

EDIT: But yeah, perl is amazingly productive once you learn in, it’s basically a better shell language, for however good shell languages are. ^.^;