Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Anonymous sub clarification

by perlfan (Curate)
on Jul 21, 2016 at 14:59 UTC ( #1168239=note: print w/replies, xml ) Need Help??


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 (Canon) 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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1168239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-11-14 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (177 votes). Check out past polls.

    Notices?