喜repeate在控制器相同的代码,所以我创建主MyApp的包装子:催化剂:我不想怎么声明全局子程序
sub do_stuff {
my $input = shift;
do something
}
但后来我想用它在控制器MyApp::Controller::Foo
sub test : Chained('base') Args(0) {
my ($self, $c) = @_;
my $test = do_stuff($c->request->params->{s});
do something more
}
我得到以下错误:
Caught exception in MyApp::Controller::Foo->test "Undefined subroutine &MyApp::Controller::Foo::do_stuff called at /home/student/workspace/MyApp/script/../lib/MyApp/Controller/Foo.pm line 24, line 1000."
我如何创建一个子程序/函数在所有Catalyst控制器中使用全局?
非常感谢,现在有效。 – theguest
@theguest太棒了。 :)另外,欢迎来到SO。如果它解决了您的问题,请点击投票下方的复选标记以接受答案。您也可以通过单击顶部指向箭头来提高答案。如果你需要帮助,请看[faq#howtoask]。 – simbabque