Search code examples
perlmojolicious

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;
};

Solution

  • 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);