Book Review: mod_perl Developers Cookbook

Perl and Apache are two of Open Sources flagship technologies. Together, they’re one of the most potent web platforms out there. Sams have just published the mod_perl Developers Cookbook to help you out with ideas when developing commercial grade applications.

As with all of these cookbooks, it is not meant to be read cover to cover (although you could), but more to be used as a reference book, something you dip in and out of when you need a specific answer. This often makes it difficult to do a proper review, so instead I shall run through some of the sections I’ve found the most useful over the past few weeks.

Getting Started

Before you can do anything you need to have a running instance of mod_perl. The first two chapters deal with installing and configuring it.

Instructions for all the major Linux distributions and packaging systems (.rpm, .deb and source) plus Windows and Mac OS X are included. For those of you that feel like living dangerously, there are also instructions on how to sync up with the bleeding edge CVS version.

Chapter 2 contains recipes on the configuration of mod_perl, including an overview of what the different modules in mod_perl actually do. There are some helpful hints for running legacy CGI scripts, improving performance and even, configuring Apache on the fly with <Perl> sections in the httpd.conf. A very powerful tool.

Manipulating the URI

Almost all web based applications, whether written in Perl, PHP, or ASP will need to manipulate the URI at some point or another. Chapter 5 contains recipes
for doing just this. Splitting a URI into its constituent parts, altering a request URI, and some more estoric uses.

For example, using recipe 5.2, you can use mod_perl to find out which &lt;Location&gt; container was responsible for processing a request. How about using the URI to force a MIME type? That would be recipe 5.6 then.

Getting Into The Guts of Apache

One of the more powerful techniques put forward is being able to use Perl to interact with all parts of the Apache life-cycle. This gives you the ability, as the book says, "to program within Apache’s framework instead of around it."

Chapters 7 & 8 show you how to create handlers and then interact with them. Chapter 9 supply recipes for tuning Apache and mod_perl. This includes limiting process growth, increasing shared memory and much much more. Practically every part of Apache can be tinkered with, in fact, if you’re a performance nut like our djc, then you’ll be in hog heaven.

The Apache Lifcycle

Once you have started to get your head round how Apache and mod_perl interact, Chapters 11 to 17 will show you some recipes and techniques that will really demonstrate why these two technologies work so well together.

Starting with a diagrammatic explanation of the Apache life-cycle (which incidentally, is one of the best explanations I’ve ever seen), and then moving onto recipes which tap into each part of this cycle, it’s easy to get overwhelmed.But if you are developing large scale Apache applications it’s worth sticking with.

Conclusion

The best way to measure how good one of these cookbooks is uses the amount of Post-it notes sticking out of the top and the amount of creases on the spine. By this benchmark, this is a pretty useful book.

It’s aimed squarely at the intermediate to advanced developer. You are going to need to understand a bit of Perl, and knowing your way around Apache and the httpd.conf will help as well. Some of the later recipes could leave even the most experienced developer scratching their head, but when you are dealing with technology this powerful that’s to be expected.

Things are not entirely perfect. Some of the recipes seem to jump from an easy concept to something which leaves you baffled without an explanatory middle step (although this could just be me, and more likely is) and there are a few errors lurking in the code examples. But these are taken care of via the books website at http://www.modperlcookbook.org. The website also contains an extensive list of related resources.

Minor quibbles aside, this is a valuable addition to any Perl Mongers bookshelf, and will make a handy addition to the Camel book.

Details

Title:
mod_perl Developers Cookbook
Authors:
Geoffrey Young, Paul Lindner and Randy Kobes
Publisher:
Sams
ISBN:
0-672-32240-4