[Kc] Book Review: Embedding Perl in HTML with Mason

Garrett Goebel garrett at scriptpro.com
Thu Apr 24 13:20:52 CDT 2003

Embedding Perl in HTML with Mason
Authors: Dave Rolsky, Ken Williams
Publisher: O'Reilly
Published: 2002_10_01
ISBN: 0596002254

"Embedding Perl in HTML with Mason" (EPIHWM) is as you might guess from the
title, a book about creating dynamic websites with the HTML::Mason module.
If you're wondering what is HTML::Mason? I don't think it would be unjust to
describing it as either a heavyweight templating system or a lightweight
application framework. I.e., it falls somewhere between Template::Toolkit
and Zope. And like Template::Toolkit, Mason need not be limited to
generating websites, but can be used to generate configuration files, static
documents, etc. This book however reflects the task Mason is most frequently
put to, that of building dynamic websites that are feature rich yet easily
maintained and extended.

Mason is built around the concept of components as building blocks. I.e.,
KISS through modularization and the elimination of redundancy. "Components"
are similar in nature to packages, but consist of text intermixed with
embedded Mason tags that allow you to take full advantage of Perl. These
components can call out to or be composed of other components. Components
can be implemented procedurally, or using inheritance, methods, attributes,
etc. In short, Mason assures that TIMTOWTDI.

As someone who is about 5 years behind the times with regard to web
development related standards and tools, and working to catch up I choose to
read "Embedding Perl in HTML with Mason" because it appeared to be the best
all round introduction to a templating system. Had Template::Toolkit had
available similar well rounded documentation I might just as easily have
started with it. Though I'll admit that the fact that Mason provides
pre-rolled solutions for caching and a lot of the management hooks that
would otherwise require a good bit of hands-on and trial by fire experience.
Though I hope never to make use of it, I also liked that Mason will work
under CGI and in a stand-alone mode. In choosing to start with Mason and
EPIHWM I was not disappointed.

The book assumes intermediate experience with Perl and passing familiarity
with HTML, Apache and CGI.pm. By intermediate, I mean that the reader should
be comfortable downloading and installing modules from CPAN and have a
passing familiarity with using object oriented interfaces. The book is
published by O'Reilly under the Open Publication License, and also freely
available at the http://www.masonbook.com website.

The authors start with an overview of Mason's features, give a short
comparison to alternative templating systems, and then move on to a through
discussion of the Mason syntax and components. They do a good job
illustrating concepts with examples throughout. They steadily work into more
advanced topics like Mason's default handlers which are similar to AUTOLOAD
in that they allow you to dynamically provide code to handle requests for
uri's that don't exist, and autohandlers which allow existent components to
easily inherit and share code. An example of a frequent use of autohandlers
would be to provide standard headers, footers, and menus.

The next few chapters flush out Mason's API, advanced features, give a
glance under the hood at how Mason works, and illustrate how Mason can take
advantage of Apache mod_perl when it is available. Finally in chapter 8, it
all comes together as the authors build a complete site using Mason. It just
so happens to be the Perl Apprentice site, which you can visit at

The last few chapters cover Mason in the absence of mod_perl, i.e., under
CGI. They then hit on scalability issues and provide various recipes for
maintaining state, authentication, authorization, and tips on sharing Mason
components to generate similar sites and working in shared development
environments. It finishes with a tutorial on subclassing and customizing
Mason itself. The appendices contain API references, tips on customizing
emacs and vim, and plug for Bricolage which is a content management system
built using Mason.

All in all, the book was a well written introduction to Mason. There were a
few typo's and the errata as usual is available at the O'Reilly website. If
you're looking to get started with Mason, look no farther. If you're looking
for advanced topics, recipes, and under the hood insights head over to
http://www.masonhq.com, read the documentation there and consider joining
the mason-users mailing list.

Garrett Goebel
IS Development Specialist

ScriptPro                  Direct: 913.403.5261
5828 Reeds Road            Main:   913.384.1008
Mission, KS 66202          Fax:    913.384.2180
www.scriptpro.com          garrett at scriptpro dot com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/kc/attachments/20030424/e866eee7/attachment.htm

More information about the kc mailing list