Apache Week

Copyright 1996-2005
Red Hat, Inc.

First published: 5th April 2002

Book Review: mod_perl Developer's Cookbook

"mod_perl Developer's Cookbook" by Geoffrey Young, Paul Lindner, and Randy Kobes which was first printed by Sams Publishing in January 2002 is a much-awaited addition to the few existing books which are exclusively about mod_perl. mod_perl is the bridge that empowers Perl and Apache users with the full strength of the Perl programming language and the Apache web server.

The primary author, Geoffrey Young is an active member of the mod_perl community and has written modules such as Apache::Clean, Apache::DebugInfo, and Apache::Dispatch amongst others which can be found on CPAN (Comprehensive Perl Archive Network, a large collection of Perl modules and documentation). Co-authors Paul Lindner, an experienced open-source developer, and Randy Kobes, a professor of physics at the University of Winnipeg in Canada, both use mod_perl extensively and have contributed modules such as HTML::Clean and Apache::WinBitHack to CPAN. The latter is no stranger to Perl books as he has written "Perl Developer's Toolkit" and co-authored "Professional Perl Development" in addition to implementing a CPAN search engine.

Perl developers who want to create Web applications by harnessing the flexibility of Apache, and mod_perl enabled Apache web site administrators are the target audience of this book. Meanwhile, the authors intended it to be a practical, hands-on reference guide containing working, real-world examples. All examples use perl 5.6.1, Apache 1.3.22, and mod_perl 1.26 built with all supported options enabled (EVERYTHING=1).

This 650-page book has 17 chapters and 3 appendixes, grouped under three main parts - Part I covers installing and configuring mod_perl, Part II covers the mod_perl API, and Part III covers each of the Apache directives provided by mod_perl. The essence of each part is summarised at the start before moving on to the individual chapters. Each chapter begins with an introduction, is then followed by subsections referred to in the book as recipes. Each recipe is for a specific task or problem and has the following format - it states the objective of the task in just one sentence, proceeds to provide the code for the task under the "Technique" subsection, and then explains what the code does under the "Comments" subsection. There are a total of 192 recipes.

Chapter 1 and 2 which are under Part I start off with the basics of installing mod_perl by using various methods from using a binary version to building it statically or as a DSO (Dynamic Shared Object) module from source on an assortment of platforms which include Linux, Solaris, Microsoft Windows, and Mac OS X. It then talks about how to configure the Apache httpd.conf file to make use of mod_perl which has just been installed.

Part II can be considered the section where you learn the theory of the fundamentals of Apache and mod_perl API. It explains how Apache processes requests in a series of phases, delves into how by using mod_perl, Perl code could be executed during any of these phases, and talks about how the mod_perl API corresponds to them. It shows you how to access the Apache request, server, and connection records, manipulate all the fields in them, looks at how Apache handles file operations, and teaches you how to write, test, debug, fine-tune, configure, package, and distribute your own mod_perl handler. The last chapter in this section explains about mod_perl's object-oriented mechanisms.

Part III is where you apply what you have learned in the previous section in real world problems. It illustrates how mod_perl handlers can be used within each of the Apache phases, and shows how the mod_perl API fits into each of the Apache phases with a nice diagram. The seven chapters under this segment explain in detail about each mod_perl Perl*Handler directive and provide scenarios where they can be used. Lastly, appendix A lists all the mod_perl hooks and build options, appendix B lists the constants to be used in mod_perl API programming, and appendix C has quite a complete list of resources followed by the index.

Overall, this is a good reference book as the source code samples make up 50% of the content so you can readily customise them to meet your requirements. The commentaries are easy to understand as they are written in a simple, narrative, and lucid style despite the numerous technical terms used. However, it could use more diagrams to illustrate complex concepts as currently flow charts, diagrams, and screen shots are used sparingly but effectively to simplify abstract ideas.

In my opinion, the best way to make full use of this book is to skim through the whole book and read only the the introduction of each part and chapters, and then the objective of each recipe. Then go back to the recipe that interests you most and study the sample code while digesting the explanation provided under the "Comments" subsection so that you may write your own Perl module using the code as a guideline.

Although this book is aimed at all Perl developers, beginners may find it difficult to grasp the concepts. The objective of the recipes can be quite distinct at times and this can disrupt the continuity and logical thought process of beginners as they move from one recipe to another sequentially. As a result, the mod_perl novice may find it difficult to gather their thoughts and digest the wealth of information provided. Therefore I find that Sams Publishing has correctly categorised this book under "User Level: Intermediate-Advanced". It is undeniable that those who are not familiar with Apache's API and mod_perl at all will be totally lost and drowning in this sea of recipes because in order for one to be able to whip up a tasty meal by using a cookbook as a guide, one must be able to identify and obtain the ingredients of the recipe beforehand.

To be fair, the authors did recommend that readers use this book alongside "Writing Apache Modules with Perl and C" by Lincoln Stein and Doug MacEachern, and the online mod_perl Guide by Stas Bekman to achieve better understanding. The authors also state that they assume and I quote them here: "that the reader has a good background in Perl, a fair understanding of Apache, and understands the basic concepts of building a Web application, Web protocols, and HTML, and in some of the more complex examples we may assume a level of mastery that exceeds the typical audience.".

Although the authors cautioned that this book is by no means comprehensive, I would say that this book is as close as a book can get to become the bible of mod_perl so if you are really serious about mod_perl, then get it by all means! It may set you back nearly 30 pounds (USD40) but it is well worth-it. Even if you are a beginner, eventually you will find this book useful after you are through with all the online mod_perl guides and documentation. Experts will have fun jumping right in, going through the recipes and rediscovering the joy of finding a dish that they have not tasted before.

For a taste of the meals yourself, you may drop in and pay a visit to its companion website where you can read through the table of contents and the sample chapters. You may also wash, cut, chop, mix, bake, stir, whip, roast, steam, sprinkle, stir-fry, fry, pinch, rinse, barbecue, eat, drink, and swallow your way through its source code repository, errata, and other resources provided. Enjoy!

Order now at Amazon.com 

This feature brought to you by: Min Min Tsan
Comments or criticisms? Please email us at editors@apacheweek.com