我正在学习 mojolicious::lite。
在路由器中,将参数委托给控制器,使用以下代码即可:
get '/hello/:name' => sub {
my $self = shift;
ControllerTest::hello($self);
};
是否有任何速记方法,例如:
get '/hello/:name' => ControllerTest::hello( shift ); #this code not work
谢谢。
我正在学习 mojolicious::lite。
在路由器中,将参数委托给控制器,使用以下代码即可:
get '/hello/:name' => sub {
my $self = shift;
ControllerTest::hello($self);
};
是否有任何速记方法,例如:
get '/hello/:name' => ControllerTest::hello( shift ); #this code not work
谢谢。
免责声明:我不是一个快乐的黑客:)
这行不通,因为 'shift' 从当前上下文(来自@_)中提取数据。我猜最短的(短手)是:
get '/hello/:name' => sub { ControllerTest::hello( shift ); };
或者也许通过使用子参考:
get '/hello/:name' => \&ControllerTest::hello
然后传入的第一个参数hello
将是传递给使用的匿名子的所有参数。我还没有尝试过,但我怀疑它会起作用:)
我认为您应该可以使用完全限定名称直接将其作为方法调用,例如
get '/hello/:name' => sub { $self->ControllerTest::hello(); };