This document provides an overview of HTML::Mason, which is a templating system that allows embedding Perl code and components in HTML pages. It discusses how Mason is used by large, dynamic websites and how it integrates with Apache via modules like mod_perl. The document also provides examples of using Mason components, handlers, and request objects to modularly design websites with reusable elements.
23. mainpage.html
<%attr>
head => quot;Wally World Homequot;
</%attr>
this is body text...
Saturday 27 October 2007 23
24. dhandlers
e.g. http://myserver/newsfeeds/LocalNews/Story1
/newsfeeds/LocalNews/Story1 => no such thing
/newsfeeds/LocalNews/dhandler => no such thing
/newsfeeds/dhandler => found! (search ends)
/dhandler
(The found dhandler would read “LocalNews/Story1”
from $m->dhandler_arg and use it as a retrieval key
into a database of stories)
Saturday 27 October 2007 24
26. dhandlers vs autohandlers
• use an autohandler when you have a set
of components to handle your pages and
you want to augment them with a
template/filter
• use a dhandler when you want to create a
set of “virtual URLs” that don't correspond
to any actual components, or to provide
default behavior for a directory
Saturday 27 October 2007 26
27. Mason Request Objects
Two global per-request objects are available to all components: $r
(provides a Perl API to current Apache request) and $m (provides a
Perl API to current Mason request)
$r->uri # the HTTP request URI
$r->content_type # set or retrieve content-type
$m->caller() # returns the calling component
$m->dhandler_arg() # returns url parts
$m->redirect(URL, [HTTP status])
Saturday 27 October 2007 27