I despise the PHP language, and I'm quite certain that I'm not alone. But the great thing about PHP is the way that mod_php takes and hides the gory details of integrating with the apache runtime, and achieves CGI-like request isolation and decent performance.

"I despise the PHP language" Welcome to the bandwagon
–
George JemptyDec 31 '08 at 12:42

2

brian, I think you're taking a bit too many liberties with people's question titles! In this one, eg, the expunged keywords "environment" and "language" were helpful. Your addition of "Power" isn't quite right, I would say (and puts words in dsadinoff's mouth). And lost the "how to do X in perl?".
–
dreevesFeb 1 '09 at 16:54

12 Answers
12

Look at Catalyst this MVC (model, view, controller) framework works stand-a-lone or with apache_perl and hides a lot of the messy bits. There is a slightly odd learning curve (quick start, slower middle, then it really clicks for advanced stuff).

Catalyst allows you to use Template Toolkit to separate the design logic from the business logic, Template toolkit really is great, even if you decide not to use Catalyst then you should be using this. HTML::Mason isn't something I personally like, although if you do all the HTML yourself then you might want to review Template::Declare which is another alternative you can also use with Catalyst.

For database stuff look at DBIx::Class, which yet again works with Catalyst or on it's own.

I don't see mixing code and HTML as a good point - it soon leads to a mess.
–
David PreciousJan 2 '09 at 17:09

@David, the opportunity to abuse this is quite tempting. It is nice not to have to learn a whole new syntax to handle flow control and data access though. IMO, the really exciting things with Mason are the autohandlers, dhandlers and component inheritance. But they aren't really like anything I know of in PHP.
–
daotoadJun 29 '10 at 19:35

If you want to take advantage of the speed of mod_perl, but the simplicity of vanilla CGI, check out the Modperl::Registry distribution from CPAN. This will allow you to run your plain CGI scripts largely unaltered.

In terms of frameworks, I'm a big fan of CGI::Application. It provides a very simple inheritance-based framework that handles most everything a web application will need to do, giving you the freedom to design your application the way you like. A simple app can be done in a monolithic fashion; a more complex one can use a full-fledged MVC design. Like Perl in general, CGI-App gives you a lot of options and generally stays out of your way.

CGI-App supports the excellent HTML::Template module by default, and has plugins for other templating systems such as the spectacular Template Toolkit. There are also a plethora of plugins for other purposes.

If you want more work done for you, check out Catalyst. This way of doing things may be more familiar if you've used Ruby on Rails.

The aforementioned Catalyst is a fine tool for constructing entire web applications, but it is by no means anywhere near simple. The primary strength of PHP is that you can embed small chunks of it as needed in otherwise static pages, i.e. you can do:

If you try to do something like this with Catalyst (as far as I know), you're developing an entire application with multiple files to print a simple value. At least, there's no explanation of how to do simple embedding in the tutorials that I saw.

Fortunately, this level of simplicity can be reached with Mason, which in some ways (thanks to the power of Perl) can be even simpler. The above example reads:

<html><body><p>The value of 2+2 is: <% 2+2 %></p></body></html>

and you get the same result.

There's no reason you can't start by installing and working with Mason and then install Catalyst side by side with it, however, if you plan to move to very complex, purely Perl-driven projects later, though.

Stuff like Catalyst and CGI::Application are more equivalents of Zend Framework rather than PHP itself. In order to replicate the basic functionality for creating web pages that PHP offers "out the box" then you need two CPAN modules that should be available in every base Perl installation:

The DBI code is slightly more complicated because it offers prepared statments and bound variables so that you don't need to worry about SQL injections. PHP doesn't offer this so you need to use something like PDO or write your own database class.

The only thing left is if you wanted HTML output in a script. But you don't want that do you? You use HTML::Template or Template::Toolkit for that, the same way you should be using Smarty or native templates in PHP.

I've worked with HTML::Mason, first hacking RT and then creating two sites with it. There's a learning curve, but it's not too bad. Worse, I think, is installing the thing, but that has much more to do with Apache and mod_perl than Mason. Once the pieces are in place, it's only as complicated as you make it (like Perl itself).