如何编写支持 CGI、FastCGI 和 mod_perl 的 Perl Web 应用程序?

发布于 2024-07-25 17:59:33 字数 347 浏览 9 评论 0原文

我如何用 Perl 编写一个 Web 应用程序,以便它可以作为普通 CGI 脚本、FastCGI / FCGI 脚本以及 mod_perl / mod_perl2 (最好仅使用核心 Perl模块和那些来自 libwww-Perl 的模块,并最大限度地减少必须安装的 Perl CPAN 模块的数量)? 我想尽量减少将脚本从使用 CGI 更改为使用 FastCGI 或 mod_perl 所需的更改。

进一步的限制:如果可能的话,我想将 Web 应用程序保留在单个文件中,而不是像目前那样将其拆分为模块。

如果重要的话,所讨论的 Web 应用程序是 gitweb,Git Web 界面。

How can I write a web application in Perl so that it can work as plain CGI script, as FastCGI / FCGI script, and from mod_perl / mod_perl2 (preferably using only core Perl modules and those from libwww-Perl, and minimizing number of Perl CPAN modules one has to install)? I'd like to minimize changes one has to do to change script from using CGI to the one using FastCGI, or mod_perl.

Further constraint: if possible, I'd like to kee web application in single file, and not split it in modules, as it is currently.

The web app in question is gitweb, Git web interface, if it matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

绻影浮沉 2024-08-01 17:59:34

我很惊讶还没有人给出明显的答案。 使用Catalyst。 使用 Catalyst,可以轻松地在任何 Web 环境中部署,包括普通 CGI、FastCGI、mod_perl 等。

I'm surprised no one's given the obvious answer yet. Use Catalyst. With Catalyst, it's trivial to deploy in any web environment, including vanilla CGI, FastCGI, mod_perl, and more.

掌心的温暖 2024-08-01 17:59:34

将功能放入模块中。 让脚本只执行一项功能:选择要实例化的应用程序模块并处理特定于平台的内容,然后委托给通用功能。 因此,您最终将得到一个要调用的脚本、三个或四个模块来实现每个平台,以及一个模块来实现一般功能。

App/bin/app.pl  

App/lib/App/Common.pm

App/lib/App/Apache1.pm
App/lib/App/Apache2.pm
App/lib/App/CGI.pm
App/lib/App/FCGI.pm

Put the functionality in modules. Make the script perform just one function: Choose which application module to instantiate and take care of platform specific stuff and then delegate to the common functionality. So, you will end up with one script to invoke, three or four modules to implement each platform, and one module to implement general functionality.

App/bin/app.pl  

App/lib/App/Common.pm

App/lib/App/Apache1.pm
App/lib/App/Apache2.pm
App/lib/App/CGI.pm
App/lib/App/FCGI.pm
枯寂 2024-08-01 17:59:34

gitweb 已经使用了 CGI,根据 文档 (免责声明:我从未测试过这一点) ,支持所有开箱即用的:

CGI.pm 在普通 CGI.pm 环境中表现良好,而且
带有对 mod_perl 和 mod_perl2 的内置支持以及
FastCGI。

最后一部分并不完全正确,因为您仍然需要 FCGI 来支持 FastCGI,这需要要安装的 C 编译器。

gitweb already uses CGI, which according to the Documentation (Disclaimer: I never tested this), supports all of those out of the box:

CGI.pm performs very well in in a vanilla CGI.pm environment and also
comes with built-in support for mod_perl and mod_perl2 as well as
FastCGI.

The last part is not exactly true, since you still need FCGI for FastCGI support, which needs a C compiler to install.

隔纱相望 2024-08-01 17:59:34

正如 Sinan 指出的,您将代码分成模块。 他没有使用神奇的术语“模型-视图-控制器”(MVC)。 您实际上是在问如何使用 MVC 并支持多个控制器。 您的模型和视图是相同的,并且不同的控制器使用它们来驱动应用程序。

As Sinan points out, you separate the code into modules. He didn't use the magic term "Model-View-Controller" (MVC). You're really asking how to use MVC and support multiple controllers. Your model and views are the same, and your different controllers use them to drive the application.

一个人练习一个人 2024-08-01 17:59:34

另一种可能的解决方案是使用 HTTP::Engine
(另请参阅 Perl 编程/HTTP::Engine 维基百科)。

Yet another possible solution would be to use HTTP::Engine
(see also Perl Programming/HTTP::Engine wikibook).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文