The Perl Journal October 2003
Practical mod_perl is simultaneously an apt and misleading title. On one hand, the book is a massive collection of practical knowledge regarding administering and programming mod_perl. On the other hand, its scope extends well beyond mod_perl, delving into aspects of web server performance and maintenance, Apache configuration, and Perl peculiarities. This is largely by necessity, but at times, the authors go overboard in their digressions. The result is a book that is full of outstanding and useful information, but that is also too large and not as organized as it could have been.
Stas Bekman and Eric Cholet's book is markedly different from O'Reilly & Associates's previous foray into mod_perl documentationLincoln Stein and Doug MacEachern's Writing Apache Modules with Perl and C (O'Reilly & Associates, 1999). The latter focused mostly on documenting the Apache 1.x API, and introduced some basic information about mod_perl programming. Bekman and Cholet focus their energies on the practical issues that arise when using mod_perl, and there are many, many, many of these.
Unlike CGI, which provides a black box where even poorly written programs will run without problems, mod_perl is closely coupled with the Apache web server. Without awareness of how Apache works, mod_perl programmers are bound to run into trouble.
For example, Apache processesand by extension, mod_perl processesare persistent. This enables you to do many things not possible with CGI: preload precompiled code, maintain persistent connections to databases, and so forth. It also means that you have to be much more diligent about your Perl code. You have to know what will happen with your global variables, and how to initialize them properly. You have to worry about closing your filehandles and destroying your objects. That's only the beginning.
Only one chapter out of 25 (namely, Chapter 6) focuses exclusively on programming mod_perl. The vast majority of the book is devoted to configuration and performance. Again, this is largely by necessity. Like many open-source projects, mod_perl is poorly documented, and much of the information in this book is not available anywhere else. Practical mod_perl also claims to be the first book to cover mod_perl 2.0, which is still in beta and whose API continues to evolve. This information alone makes the book valuable, as mod_perl 2.0 is essentially undocumented.
Unfortunately, the authors go into too much detail in certain areas, and not enough in others, and the tradeoff is significant. For example, Part 2 discusses mod_perl performance, and contains a tremendous amount of useful knowledge, such as how to configure a mod_perl-enabled web server with an http proxy. However, one of its chapters (Chapter 8) delves into choosing the right platform and includes a substantial section on hardware. Not only was much of this information gratuitous, some of its advice was questionable.
Part 4 focuses on debugging, which would have been a good (and much thinner) book in and of itself. Once again, there was much useful information (for example, running httpd in single-process mode, the Devel::ptkdb module, and so on), but there was also a section on debugging using print statements, which was completely unnecessary.
Contrast this with the first part of Chapter 6, which describes some unusual behavior in an innocent-looking mod_perl application. To make a long story short, a subroutine that looks like it is referring to a lexical variable defined outside of its scope is actually a closure, because of the way mod_perl loads applications. That's a mouthful, and it requires a more advanced understanding of how Perl handles scoping. You could argue that this topic is beyond the scope of this book, but I would have found a more extensive chapter on scoping issues more valuable than a section on debugging using print statements.
I think that Practical mod_perl could lose a few hundred pages and be a better (and cheaper) book. That said, the authors faced a difficult balancing act, and in the end, I'm glad that they erred on the side of too much information. It's worth reading the book front-to-back, skimming through some of the less useful parts, because the accumulated knowledge in the book is broad, and you may find tips where you least expect it. For instance, prior to reading this book, I did not know that mod_perl could be used to configure Apache, a technique that I now plan to use on some of my projects. Ultimately, most mod_perl programmers will find Practical mod_perl valuable.
TPJ