拥有下一个简单的 Plack 应用程序:
use strict;
use warnings;
use Plack::Builder;
my $app = sub {
return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
};
builder {
foreach my $act ( qw( /some/aa /another/bb / ) ) {
mount $act => $app;
}
};
返回的错误:
WARNING: You used mount() in a builder block, but the last line (app) isn't using mount().
WARNING: This causes all mount() mappings to be ignored.
at /private/tmp/test.psgi line 13.
Error while loading /private/tmp/test.psgi: to_app() is called without mount(). No application to build. at /private/tmp/test.psgi line 13.
但是下一个构建器块是可以的。
builder {
foreach my $act ( qw( /some/aa /another/bb / ) ) {
mount $act => $app;
}
mount "/" => $app;
};
我比Plack::Builder 手册说的更了解
注意:在构建器代码中使用 mount 后,您必须对所有路径使用 mount,包括根路径 (/)。
但是在for
循环中,我将/
坐骑作为最后一个:qw( /some/aa /another/bb / )
,所以幕后有一些东西。
有人可以解释一下吗?