Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What "ladder sub {...}" means in perl?

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;
};
like image 678
Hao Avatar asked May 22 '18 03:05

Hao


1 Answers

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);
like image 104
mob Avatar answered Oct 22 '22 04:10

mob