http://www.perlmonks.org?node_id=1168239


in reply to Anonymous sub clarification

As LanX said, it's just a parenthesis-less method call to "get". "=>" is often called a "fat comma" in Perl; but more over it's like passing an anonymous hash to the "get" method as implemented by Mojo.
IOW, it's also equivalent to the following where "/" is the hash key and anonymous subroutine is the hash value:
my $hash_ref = { '/' => sub {...} }; get($hash_ref);
And for that matter,
my $array_ref = [ '/', sub {...} ]; get($array_ref);
Ultimately, you are associating the subroutine handler for the URL; in this case, "/".

Replies are listed 'Best First'.
Re^2: Anonymous sub clarification
by haukex (Archbishop) on Jul 21, 2016 at 17:37 UTC

    Hi perlfan,

    I just tested this with Mojolicious::Lite, and I had to dereference the hash/array with get(%$hash_ref); / get(@$array_ref); for it to work.

    Regards,
    -- Hauke D

      Cool, then I was close. I didn't test it and I don't use Mojo, but I think I made my point. Thanks!