Chapter 5. Advanced Features
In the previous chapters you have been introduced to the basic features of Mason, and you should have a fairly good idea by now of how you might actually go about constructing a dynamic web site from Mason components. You have seen a few of Mason’s unique features, such as the autohandler mechanism, the dhandler mechanism, and the ability to pass arbitrary data between components.
In this chapter we’ll go beyond the basics and learn more about advanced ways to use Mason components to design large dynamic sites. You’ll learn how to define multiple components in the same text file, how to create components on the fly from Perl strings, how to manage multiple component root directories, and (finally!) how to use all of Mason’s object-oriented features.
Subcomponents
Although we often imagine a one-to-one correspondence between text
files and Mason components, it is actually possible to define
multiple components in a single text file. This is achieved by using
a <%def></%def> block, a special Mason
directive that defines one component from within another. The
component embedded within the
<%def>
block is called a
subcomponent
,
and it is visible only to the component within which it resides:
component A may not access component B’s
subcomponents directly.
The subcomponent may use any of the standard Mason component
directives, such as <%args>,
<%init>, %-lines, and so
on. The only exceptions are that you may not use
<%def> or <%method> blocks within subcomponents ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access