【发布时间】:2017-06-07 16:22:48
【问题描述】:
我有一个大约 15 岁的 Perl 应用程序。 该应用程序在 Apache 上运行,示例代码如下所示:
use Apache2::RequestUtil ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK);
sub handler {
my $r = shift;
Apache2::RequestUtil->request($r)
$r->subprocess_env;
$r = Apache2::RequestUtil->request;
$r->content_type("text/html");
$r->print("Hello World");
};
return Apache2::Const::OK;
}
1;
这可行,但现在我想将 Mojolicious 用于此应用程序的新功能。 但是我怎样才能将 Mojolicious 集成到这个应用程序中呢? 当我执行以下操作时
use Apache2::RequestUtil ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK);
sub handler {
my $r = shift;
Apache2::RequestUtil->request($r
$r->subprocess_env;
$r = Apache2::RequestUtil->request;
get '/:foo' => sub {
my $self = shift;
my $foo = $self->param('foo');
$self->render(text => "Hello from $foo.");
};
return Apache2::Const::OK;
}
app->start;
1;
我得到一个空白页。是否可以将 Mojo 集成到我的应用中?
【问题讨论】:
-
您在第二个示例中是否加载了任何与 mojo 相关的内容?看起来不像。它怎么知道有
get函数? Mojolicious 有一种与 mod_perl 接口的方法。我不知道它是如何工作的,但有文档。我怀疑它可以通过 PSGI 工作。您可能会将您的新功能放入一个单独的应用程序中,该应用程序可以进入它自己的文件,在此处加载并使用它。 -
对不起,有使用 Mojolicious::Lite;在第二个例子中。刚刚忘记复制了。
-
请edit 并包含更多该代码。如果有的话,也是一个包名。
标签: apache perl mojolicious mod-perl