简体   繁体   中英

How does one build a website in Perl without CGI?

I asked a separate question about Python here , and was told that "classic CGI isn't the best way to use anything at all. With classic CGI server has to spawn a new process for every request"

Now I am working on a Perl-based website using Apache, and all my scripts start with:

use CGI;

Is this a problem? Is there a newer or better way to build a Perl-based website?

Write your website using Plack or a framework built on top of Plack (such as Catalyst or Dancer / Dancer2 ).

You then have several options to deploy the website. You can deploy it as a CGI script (easy to do, but inefficient), or using FastCGI or Apache's mod_perl, or forget Apache altogether and use a standalone Perl web server such as Starman . Yet another option is uWSGI which is conceptually similar to FastCGI.

Apache's mod_proxy allows you to take a hybrid approach for deployment. Your website could be running on Apache, which could forward requests for particular URLs through to Starman.

The CGI perl module is a way of interfacing with a webserver. It does the job it was always intended to, but it's been superseded by an assortment of frameworks for web development.

It has been removed from the perl core :

The rational for this decision is that CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time. These will be documented with The rational for this decision is that CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time. These will be documented with CGI::Alternatives

However, there's a bit of a learning curve for the assorted frameworks, and personally I find them geared up to 'proper wesbites' - not the 'script with a web interface' type things I tend to knock together. So I'd suggest reading though those alternatives, and if you're trying to do something clever - use one of them.

And if you're not, you probably didn't really need CGI in the first place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM