The Compiler is
responsible for turning a hierarchical
component structure, as fed to it by the Lexer, into a usable form.
The default Compiler is
HTML::Mason::Compiler::ToObject, which creates a
Creates a new Compiler object and returns it. Called by the Interpreter object. See Appendix B for a list of parameters accepted.
Returns a list of variable names (including the initial
type-identifying sigil) that have been declared as allowable globals
within components or the number of such variables in a scalar
context. The list of allowed globals can optionally be set by passing
the variable names (again, including the initial sigils) as
arguments. This replaces any previously set globals. To clear the
list of allowed globals, pass an argument list containing the single
my @allowed = $compiler->allow_globals; # Get list of globals $compiler->allow_globals('$dbh','%session'); # Set list of globals $compiler->allow_globals(undef); # Clear list of globals
Adds one or more variable names (including the initial
type-identifying sigil) to the list of globals allowed within
components. Returns a list of variable names (again, including the
initial sigils) in a list context or the number of such variables in
a scalar context.
Returns a string identifier that uniquely identifies this compiler and its current settings. This identifier is used mainly to make sure that components compiled under a different compiler, or under the same compiler with different settings, are declared stale.
Compiles a component from source text and returns the compiled
component. The source text is passed in a
comp_source parameter, and a unique identifier for
this component is passed in a mandatory
parameter. The compiled component may take any of several forms, but
returns a bunch of Perl code in a string.
Called by the Lexer when it starts processing a component.
Called by the Lexer when it finishes processing a component.
Called by the Lexer when it encounters an opening Mason block tag
<%args>. Its main purpose is to keep track
of the nesting of different kinds of blocks within each other. The
type of block (
once, etc.) is passed via the
Called by the Lexer when it encounters a closing Mason block tag like
start_block( ), its main purpose is to help maintain syntactic
Several compiler methods like
are called by the Lexer after
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
text_block( ), and
raw_block( ). The last method is called for all
Inserts the text contained in a
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
%, 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
Inserts a key/value pair from a
<%attr> section into the component.
block_type parameter will be
in this section, but starts a
Called by the Lexer to end a “named” block.
Called by the Lexer when it encounters a substitution tag
<% ... %>).
The value of the
will be everything found after the pipe (|) in the substitution tag
and may be more than one character such as
Called by the Lexer when it encounters a component call tag without
embedded content (
<& ... &>).
call parameter contains the
entire contents of the tag.
Called by the Lexer when it encounters a component call tag with
embedded content (
<&| ... &>).
Called by the Lexer when it encounters an end tag for a component
call with content (
</&>). Note that
there is no corresponding
method for component calls without content, because these calls
don’t have end tags.