I'm reading tweetylicious source from github to study Mojolicious framework:
However I'm confused by below piece of code ladder sub ...
. What does it mean in Perl? It looks like not a regular Perl grammar.
Btw, I'm with Strawberry Perl 5.
# The rest of the routes are specific to logged in users, so we
# add a ladder to make sure (instead of making sure inside each route)
ladder sub {
my $self = shift;
return 1 if $self->session('name');
$self->redirect_to('/login') and return;
};
It is a call to a subroutine called ladder
that expects a code reference as its first argument. It is equivalent to
$tmpfunc = sub {
my $self = shift;
return 1 if $self->session('name');
$self->redirect_to('/login') and return;
};
ladder($tmpfunc);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With