Review on the book "Embedding Perl in HTML with Mason"
Embedding Perl in HTML with Mason written by Dave Rolsky and Ken Williams, published by O'Reilly Media, Inc., in Oct 2002.
This is the definitive guide on Mason, the powerful Perl based template management system written by two active Mason developers. You can use Mason to build dynamic web sites or manage your documents. Despite the fact that the book was written about six years before this review was written, it is still very helpful for Mason users.
To use this book effectively, you need to be an intermediate-level Perl developer. For example, you should feel comfortable working with Perl modules including installing them from CPAN.
In the first chapter, the authors introduce the major features of Mason and compare it with some alternatives including PHP and some Perl based template systems. The authors also give a few short examples of Mason code. You can consult our Mason setup guide to see how to install Mason in an Apache 2.x/mod_perl 2.x environment.
In Chapter 2, the authors describe how to write Mason components which constitute the building blocks of your web sites or documents. You can mix plain text and Perl code freely so that your component can generate whatever content your need. In fact, if you are an experienced Perl developer, you can put down this book for now and start playing with Mason because the basics have been covered well enough.
Once you become more experienced with Mason, you may feel the need to use Mason's more advanced features, such as auto and default handlers. They allow you to add common elements such as headers and footers to all your pages automatically or serve some pages on the fly without them being physical files on disk, e.g., generating book reviews from database tables based the given URL. For example, if visitors ask for any /review/<book_isbn> you can serve it through a default handler. These special handlers are discussed in detail in Chapter 3. While you are here, it is also good to review Chapter 4 which serves as a reference for the Mason APIs so you know where to look for when you need it.
If you use Mason to create dynamic web pages, you can read Chapter 7 to see how to use it with mod_perl. If you have to use CGI, then Chapter 9 is a must read. For a full example of using Mason to build a dynamic web site, you can read Chapter 8. However, please keep it in mind that the authors mostly use this chapter to showcase various techniques of using Mason. To create a more manageable web site, you may instead need to consider using the Catalyst framework or the Bricolage content management system, the latter of which is covered briefly in the Appendix D of this book. In Chapter 10, the authors discuss scalable web design and suggest you keep Mason component mostly limited to output generation.
In Chapter 11 the authors discuss some recipes and probably the most useful is about using Mason outside web server's context. As an example, we use Mason to generate all the web pages for an alumni web site and then upload them to the server. You can check our article on design and maintenance of the SJTU-SV.com web site for details.
You may notice that we don't mention Chapters 6 and 12 which talk about the Mason core classes and how to extend them. We think probably most readers don't need to do that in the majority of their daily tasks. However it is nice to know that you can read them for more information should you ever need that.
The authors have graciously put the whole book online at http://masonbook.com/book/.