Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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 (Chancellor) 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.

    -- 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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-05-25 02:45 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (143 votes). Check out past polls.