Book Reviews

The following book reviews are the copyright of their respective authors and no part should be reproduced without the express permission of the author. Publishers and Authors of the books reviewed may reproduce the whole or extracts of a review for their book. To request copyright permission please email webmaster@birmingham.pm.org.

All the reviews herein are the opinions of the reviewer and are not necessarily the views of Birmingham Perl Mongers and its members. If you feel a review or comment has been made in error, please contact webmaster@birmingham.pm.org to rectify the situation.

Perl Books

Static Link: http://birmingham.pm.org/reviews/7

 
Practical mod_perl
Title:Practical mod_perl
Author(s):Stas Bekman, Eric Cholet
ISBN:0-596-00227-0
Publisher:O'Reilly Media
Reviewer:Jon Brookes

It is fair to say that most if not all O'Reilly titles are well written, useful to the computer professional and crafted with a bent toward practical use rather than mere academic re-writes of manual pages and design documentation.

Practical mod_perl is no exception to this, indeed with the word 'Practical' in it's title, one would expect such a work to be an in depth 'hands on' guide to mod_perl. This is very much the case. Using the introduction as a 'quick start', the eager can get up and running with simple mod_perl scripts before page 40.

The introductory sections run through the basic mechanisms of CGI and HTTP, running CGI.pm scripts under mod_perl, simple mod_perl 'content handlers' and even mod_perl win32 implementation and considerations are explained concisely and by example where appropriate. One could ask, 'is this all I need to know?'. The text answers this in a qualified manner as 'yes and no'. Naturally, the reader would be well advised to go with the latter as there is clearly much to learn about mod_perl beyond simply porting existing CGI.pm based scripts to run as compiled objects under mod_perl. The following 800+ pages testify to this.

The book is separated into 'parts' - each of which are often a book in their own right.

Part I - mod_perl Administration

Installation of mod_perl can be as simple as 'perl Makefile.pl; make; make install' but chapter 3 discusses this and more installation and configuration options that you could shake a stick at. Discussion of compilation of options for 'DSO' (Dynamic Shared Objects), apxs, SSL, Stronghold and even installation via CPAN.pm are sections that the reader will be wise to re-visit, particularly when it it is time for a new install or upgrade. Of course, compilation options may change with the arrival of new versions of mod_perl and Apache however this section should still be a very good starting point together with the latest README and INSTALL files.

Correct configuration of an existing or newly compiled system is sure to be up for review prior to go-live and over time thereafter. The text's walk through approach to mod_perl and Apache configuration files and options is straight forward and clear. There is attention to detail throughout such as an example of setting 'taint checking' via the httpd.conf directive 'PerlTaintCheck on'. Further evidence of the book's practical approach is an explanation of how, when a first configuration has been implemented into a production environment, the 'fear of changing' this and potentially breaking service can be avoided by the use of methods such as 'apachectl configtest'.

The day to day care of mod_perl system gets a chapter all of it's own, discussing start-up, shut-down, log file rotation and all that would be good for a sys-admin to read and digest.

Chapter 6 'Coding with mod_perl in mind' claims to be 'the most important chapter' and with this the reader would likely agree. The usual considerations such as the correct use of global variables, use of 'strict', correct use of scoping and modular implementation are all here. There are more goodies to be found such as an introduction to debugging with Apache::DB where poorly implemented mod_perl scripts that are misbehaving can be more simply debugged by having their activity logged to a text file. The section dealing with how to make the jump to using 'Apache Handlers' from a CGI.pm centred application is to me a primary reason for saying 'no' to the above 'is this all I need to know?' question.

Part II - mod_perl Performance

mod_perl Performance, is also illustrative of the text's practical approach to mod_perl, wherein facts are backed up with 'investigative details'. Not just the usage of say, 'Benchmark' module is here but also example outputs together with explanations. Some may have stretched just this section to another book but our authors give us this as part of the whole.

Simply porting to mod_perl will gain significant speed increases but the reader is inspired to push performance further than just the initial gains. The example of 'requests per second' against 'max clients' should not only start us on the road to benchmarking performance but also justifying current and further investments of development time and hardware.

TMTOWTDI - Chapter 13 is a title that I like.

'There's more than one way to do it' can be misapplied in the real world IMO and could thus be extended to include 'but some ways are silly, others less so and yet some more sensible'. It is true to say that there must be trade-offs dependent on a given situation.

There are no nonsensical ideas purported by Stas and Eric but the balance between what is faster for a particular application and what may be easier/more familiar to code is reasonably argued. Apache::Registry .vs. 'Pure Perl handlers' is a case in point.

Part III - Databases and mod_perl

Databases and mod_perl gets a look in but with not so much coverage as other topics. Perhaps this may be expanded on in a future release or is maybe already adequately covered by other texts.

Part IV - Debugging and Troubleshooting

Some of Part IV is not really pure mod_perl at all. It is simply encouraging the use of 'good Perl' in terms of best coding practice, style and method. If the reader had got to this point in the book and for some reason decided not to use mod_perl, the text's exploration of the former would be of value in any case.

Highlights of Debugging and Troubleshooting were topics such as :

  • What warnings and errors 'really are', that is, should we ignore warnings and where do we find the outputs of warnings when running under mod_perl? I like in particular the practical application of warnings as suggested in the 'development environment' and the disabling of said same when your 'perfected' code is transported to the live environment. Warnings and also 'diagnostics' - another topic of interest, of course eat up processing power. So our authors suggest to use them in the development environment to find all your imperfections and bugs but remove this feature in the live one.
  • Better handling of 'die' conditions in the case of error handling - there are CPAN approaches to this but also 'assigning signal handlers' to a custom Perl sub the reader may also find of interest.
  • Use of the Perl debugger. This is discussed as run from the shell and also from within mod_perl run time environment. There is a gentle walk through an interactive debug session that should help those not accustomed to the debugger to gain a working knowledge of the tool set.
  • 'strace' - Similar to the discussion of the debugger, a walk through is given to track, for example, system errors
  • A discussion of some CPAN modules specific to debugging and other tools such as the Perl Tk GUI debugger

Part V - mod_perl 2.0

This section brings out the key differences between the current and later version of Apache2 and mod_perl 2.0 but with a minor caveat. The reviewer did not find this section on 'mod_perl 2.0' as 'hands on' or at least 'practical' as the preceding sections were on Perl, mod_perl and the environment that these run in. This could well be because not so much emphasis was put onto mod_perl 2.0 at the time of writing as no doubt will become necessary as the march of time goes onward.

Part VI - Appendixes

The appendixes add value for money in the form of a short 'cook book' approach to the use of modules for The Template Toolkit, AxKit, XML and what you should be looking for from ISPs that offer mod_perl.

Summary

It would be hard to pinpoint a 'best chapter' or 'section' but in the reviewers personal point of view, 'Part IV - Debugging and Trouble Shooting' is likely to be of immediate benefit as is often the case, sites get implemented in mod_perl without first measuring the true cost of testing and all the implications of writing with 'clean code'. Thus live sites need debugging NOW and this chapter has already been of interest / use in starting a strategy to correct flaws that have already slipped into production code.

The sections of the book (1 through 6) pretty much stand alone but do sequentially build on a body of knowledge from start to finish. It would be unfair to class this as a 'tree killer' (some texts of this size and typically by other press companies have a lot of 'filler' chapters that don't say or do a lot and seem to be there to justify their high shelf price). Despite its size, Practical mod_perl covers a lot of material, each sub-section is quite concise and uses a relatively short space and is presented in a 'practical' manner :).

The dollar price, at $50 is cost effective if you are using or thinking of using mod_perl to implement your web site. If you use Perl anyway for your web site, then really mod_perl is a logical progression to make and subsequently this text must become a 'must have' procurement at some point.

The reviewer is quite happy to purchase a mighty tome such as 'Practical mod_perl' but a somewhat trite criticism could be that the physical weight of this book could strain all but the less delicate wrists. In the wrong hands, the book would make a hefty paper weight or door stop. However in terms of 'pages for you buck' this should all be a plus. As mentioned above, perhaps Part III is a bit on the short side to warrant a section but eventual acceptance of 'mod_perl 2.0' as a base install on most platforms will likely trigger a revision of this text anyway, which may incidentally have more to say on the DBI front.

At present, it could be argued that this is likely still one of the best texts on mod_perl (covering both older versions of mod_perl and mod_perl 2.0) one can get.

- Jon Brookes, Oct 2003