HTML::Mason::Compiler - Compile Mason component source
package My::Funky::Compiler; use base qw(HTML::Mason::Compiler);
The compiler starts the compilation process by calling its lexer's
lex
method and passing itself as the compiler
parameter. The
lexer then calls various methods in the compiler as it parses the
component source.
List of variable names, complete with prefix ($@%
), that you intend
to use as globals in components. Normally global variables are
forbidden by strict
, but any variable mentioned in this list is
granted a reprieve via a "use vars" statement. For example:
allow_globals => [qw($DBH %session)]
In a mod_perl environment, $r
(the request object) is automatically
added to this list.
Escape flags to apply to all <% %> expressions by default. The current valid flags are
h - escape for HTML ('<' => '<', etc.) u - escape for URL (':' => '%3A', etc.)
The developer can override default escape flags on a per-expression basis; see the escaping expressions section of the developer's manual.
If you want to set multiple flags as the default, this should be given as a reference to an array of flags.
All of the above properties have read-only accessor methods of the same name.
You cannot change any property of a compiler after it has been created - among other things, this would potentially invalidate any existing cached component objects or object files. Your best bet is to create different compiler objects and load them into different interpreters.
There are several methods besides the compilation callbacks below that a Compiler subclass needs to implement.
These are methods called by the Lexer while processing a component source. You may wish to override some of these methods if you're implementing your own custom Compiler class.
<%perl>
or <%args>
. Its main purpose is
to keep track of the nesting of different kinds of blocks within each
other. The type of block ("init", "once", etc.) is passed via the
"block_type" parameter.
</%perl>
or </%args>
. Like
start_block()
, its main purpose is to help maintain syntactic
integrity.
Several compiler methods like doc_block()
, text_block()
, and
raw_block()
are called by the Lexer after start_block()
when it
encounters blocks of certain types. These methods actually do the
work of putting the body of a block into the compiled data structure.
The methods that follow this pattern are init_block()
,
perl_block()
, doc_block()
, text_block()
, and raw_block()
.
The last method is called for all <%once>
, <%cleanup>
,
<%filter>
, <%init>
, <%perl>
, and <%shared>
blocks.
Inserts the text contained in a text
parameter into the component
for verbatim output.
This is called when the lexer finds plain text in a component.
Inserts a variable declaration from the <%args>
section into
the component.
The type will be either "$", "@", or "%", indicating a scalar, array,
or hash. The name is the variable name without the leading sigil.
The default is everything found after the first "=>" on an <%args>
block line, and may include a comment.
Inserts a key-value pair from a <%flags>
or <%attr>
section into the component.
The "block_type" parameter will be either "flags" or "attr".
<%method>
or <%def>
).
Called by the Lexer when it encounters a substitution tag
(<% ... %>
).
The value of the "escape" parameter will be everything found after the pipe (|) in the substitution tag, and may be more than one character such as "nh".
Called by the Lexer when it encounters a component call tag without
embedded content (<& ... &>
).
The "call" parameter contains the entire contents of the tag.
<&| ... &>
).
</&>
). Note that there is no corresponding
component_call_end()
method for component calls without content,
because these calls don't have ending tags.
%
-line.
We recommend that any parameters you add to Compiler be read-only, because the compiler object_id is only computed once on creation and would not reflect any changes to Lexer parameters.