我正在阅读tweetylicious source from github来研究Mojolicious框架:
但是我对下面的代码ladder sub ...
感到困惑。 Perl是什么意思?它看起来不像普通的Perl语法。
# 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;
};
答案 0 :(得分:9)
调用一个名为ladder
的子例程,它希望将代码引用作为其第一个参数。它相当于
$tmpfunc = sub {
my $self = shift;
return 1 if $self->session('name');
$self->redirect_to('/login') and return;
};
ladder($tmpfunc);