我正在阅读github上的tweetylicious源码来研究Mojolicious框架:
但是我对下面的代码感到困惑ladder sub ....Perl是什么意思?它看起来不像普通的Perl语法.
顺便说一下,我和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;
};
Run Code Online (Sandbox Code Playgroud) 我对Perl Named Blocks感到困惑(我以为它们是......).以下是一个例子:
#!/usr/bin/perl
sub Run(&){
my ($decl) = @_;
$decl->();
}
sub cmd(&){
my($decl) = @_;
my(@params) = $decl->();
print "@params\n";
}
sub expect(&){
my ($decl) = @_;
my(@params) = $decl->();
print "@params\n";
}
Run {
cmd { "echo hello world " };
expect { exit_code => 0, capture => 2};
};
Run Code Online (Sandbox Code Playgroud)
注意最后一行.它看起来像"Run","cmd","expect"是命名块,但不是函数.有谁知道它们是什么?任何可用的链接介绍它们?我找不到任何这种语法的参考.