- PARAMETERS TO THE new() CONSTRUCTOR
- SEE ALSO
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.
PARAMETERS TO THE new() CONSTRUCTOR
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.
The Lexer object to associate with this Compiler. By default a new object of class lexer_class will be created.
The class to use when creating a lexer. Defaults to HTML::Mason::Lexer.
Sub reference that is called to preprocess each component before the compiler does it's magic. The sub is called with a single parameter, a scalar reference to the script. The sub is expected to process the script in-place. This is one way to extend the HTML::Mason syntax with new tags, etc., although a much more flexible way is to subclass the Lexer or Compiler class. See also postprocess_text and postprocess_perl.
Sub reference that is called to postprocess the text portion of a compiled component, just before it is assembled into its final subroutine form. The sub is called with a single parameter, a scalar reference to the text portion of the component. The sub is expected to process the string in-place. See also preprocess and postprocess_perl.
Sub reference that is called to postprocess the Perl portion of a compiled component, just before it is assembled into its final subroutine form. The sub is called with a single parameter, a scalar reference to the Perl portion of the component. The sub is expected to process the string in-place. See also preprocess and postprocess_text.
There are several methods besides the compilation callbacks below that a Compiler subclass needs to implement.
- compile(comp_source => <string>, name => <string>, comp_class => <string>)
The "comp_class" parameter may be ignored by the compiler.
This method should return a unique id for the given compiler object. This is used by the interpreter when loading previously compiled objects in order to determine whether or not the object should be re-compiled.
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.
This method is called by the Lexer when it starts processing a component.
This method is called by the Lexer when it finishes processing a component.
- start_block(block_type => <string>)
This method is called by the Lexer when it encounters an opening Mason block tag like
<%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.
- end_block(block_type => <string>)
This method is called by the Lexer when it encounters a closing Mason block tag like
start_block(), its main purpose is to help maintain syntactic integrity.
- *_block(block => <string>, [ block_type => <string> ])
Several compiler methods like
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
raw_block(). The last method is called for all
- text(text => <string>)
Inserts the text contained in a
textparameter into the component for verbatim output.
This is called when the lexer finds plain text in a component.
- variable_declaration( type => <string>, name => <string>, default => <string> )
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.
- key_value_pair(block_type => <string>, key => <string>, value => <string>)
Inserts a key-value pair from a
<%attr>section into the component.
The "block_type" parameter will be either "flags" or "attr".
- start_named_block(block_type => <string>, name => <name>)
Analogous to item_start_block, but starts a "named" block (
Called by the Lexer to end a "named" block.
- substitution(substitution => <string>, escape => <string>)
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".
- component_call(call => <string>)
Called by the Lexer when it encounters a component call tag without embedded content (
<& ... &>).
The "call" parameter contains the entire contents of the tag.
- component_content_call(call => <string>)
Called by the Lexer when it encounters a component call tag with embedded content (
<&| ... &>).
Called by the Lexer when it encounters an ending tag for a component call with content (
</&>). Note that there is no corresponding
component_call_end()method for component calls without content, because these calls don't have ending tags.
- perl_line(line => <string>)
Called by the Lexer when it encounters a