The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML::Mason::Compiler - Compile Mason component source</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">


<!-- INDEX BEGIN -->
<div name="index">
<p><A NAME="__index__"></a></p>

<ul>

	<li><A HREF="#name">NAME</a></li>
	<li><A HREF="#synopsis">SYNOPSIS</a></li>
	<li><A HREF="#description">DESCRIPTION</a></li>
	<li><A HREF="#parameters_to_the_new___construc">PARAMETERS TO THE <code>new()</code> CONSTRUCTOR</a></li>
	<li><A HREF="#accessor_methods">ACCESSOR METHODS</a></li>
	<li><A HREF="#methods">METHODS</a></li>
	<ul>

		<li><A HREF="#compilation_callbacks">Compilation Callbacks</a></li>
	</ul>

	<li><A HREF="#subclassing">SUBCLASSING</a></li>
	<li><A HREF="#see_also">SEE ALSO</a></li>
</ul>

<hr name="index" />
</div>
<!-- INDEX END -->

<p>
</p>
<h1><A NAME="name">NAME</a></h1>
<p>HTML::Mason::Compiler - Compile Mason component source</p>
<p>
</p>
<hr />
<h1><A NAME="synopsis">SYNOPSIS</a></h1>
<pre>
  package My::Funky::Compiler;</pre>
<pre>
  use base qw(HTML::Mason::Compiler);</pre>
<p>
</p>
<hr />
<h1><A NAME="description">DESCRIPTION</a></h1>
<p>The compiler starts the compilation process by calling its lexer's
<code>lex</code> method and passing itself as the <code>compiler</code> parameter.  The
lexer then calls various methods in the compiler as it parses the
component source.</p>
<p>
</p>
<hr />
<h1><A NAME="parameters_to_the_new___construc">PARAMETERS TO THE <code>new()</code> CONSTRUCTOR</a></h1>
<dl>
<dt><strong><A NAME="allow_globals" class="item">allow_globals</a></strong></dt>

<dd>
<p>List of variable names, complete with prefix (<code>$@%</code>), that you intend
to use as globals in components.  Normally global variables are
forbidden by <code>strict</code>, but any variable mentioned in this list is
granted a reprieve via a &quot;use vars&quot; statement. For example:</p>
<pre>
    allow_globals =&gt; [qw($DBH %session)]</pre>
<p>In a mod_perl environment, <code>$r</code> (the request object) is automatically
added to this list.</p>
</dd>
<dt><strong><A NAME="default_escape_flags" class="item">default_escape_flags</a></strong></dt>

<dd>
<p>Escape flags to apply to all &lt;% %&gt; expressions by default. The current
valid flags are</p>
<pre>
    h - escape for HTML ('&lt;' =&gt; '&amp;lt;', etc.)
    u - escape for URL (':' =&gt; '%3A', etc.)</pre>
<p>The developer can override default escape flags on a per-expression
basis; see the <A HREF="Devel.html#escaping_expressions">escaping expressions</a> section of the developer's manual.</p>
<p>If you want to set <em>multiple</em> flags as the default, this should be
given as a reference to an array of flags.</p>
</dd>
<dt><strong><A NAME="enable_autoflush" class="item">enable_autoflush</a></strong></dt>

<dd>
<p>True or false, default is true. Indicates whether components are
compiled with support for <A HREF="Params.html#autoflush">autoflush</a>. The component can be compiled
to a more efficient form if it does not have to check for autoflush
mode, so you should set this to 0 if you can.</p>
</dd>
<dt><strong><A NAME="lexer" class="item">lexer</a></strong></dt>

<dd>
<p>The Lexer object to associate with this Compiler. By default a new
object of class <A HREF="Params.html#lexer_class">lexer_class</a> will be created.</p>
</dd>
<dt><strong><A NAME="lexer_class" class="item">lexer_class</a></strong></dt>

<dd>
<p>The class to use when creating a lexer. Defaults to <a HREF="Lexer.html">HTML::Mason::Lexer</a>.</p>
</dd>
<dt><strong><A NAME="preprocess" class="item">preprocess</a></strong></dt>

<dd>
<p>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
<A HREF="Params.html#postprocess_text">postprocess_text</a> and <A HREF="Params.html#postprocess_perl">postprocess_perl</a>.</p>
</dd>
<dt><strong><A NAME="postprocess_text" class="item">postprocess_text</a></strong></dt>

<dd>
<p>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
<A HREF="Params.html#preprocess">preprocess</a> and <A HREF="Params.html#postprocess_perl">postprocess_perl</a>.</p>
</dd>
<dt><strong><A NAME="postprocess_perl" class="item">postprocess_perl</a></strong></dt>

<dd>
<p>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
<A HREF="Params.html#preprocess">preprocess</a> and <A HREF="Params.html#postprocess_text">postprocess_text</a>.</p>
</dd>
<dt><strong><A NAME="use_source_line_numbers" class="item">use_source_line_numbers</a></strong></dt>

<dd>
<p>True or false, default is true. Indicates whether component line
numbers that appear in error messages, stack traces, etc. are in terms
of the source file instead of the object file. Mason does this by
inserting '#line' directives into compiled components.  While source
line numbers are more immediately helpful, object file line numbers
may be more appropriate for in-depth debugging sessions.</p>
</dd>
</dl>
<p>
</p>
<hr />
<h1><A NAME="accessor_methods">ACCESSOR METHODS</a></h1>
<p>All of the above properties have read-only accessor methods of the
same name.</p>
<p>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.</p>
<p>
</p>
<hr />
<h1><A NAME="methods">METHODS</a></h1>
<p>There are several methods besides the compilation callbacks below that
a Compiler subclass needs to implement.</p>
<dl>
<dt><strong><A NAME="compile" class="item">compile(...)</a></strong></dt>

<dd>
<p>This method has several parameters:</p>
<ul>
<li><strong><A NAME="comp_source" class="item">comp_source (required)</a></strong>

<p>Either a scalar or reference to a scalar containing the component source.</p>
</li>
<li><strong><A NAME="name" class="item">name (required)</a></strong>

<p>The name of the component. This should be the filename of the
component if it is file-based, or some other clear identifier of the
component source.</p>
</li>
<li><strong><A NAME="comp_path" class="item">comp_path (required)</a></strong>

<p>This should be the component's path.</p>
</li>
<li><strong><A NAME="fh" class="item">fh (optional)</a></strong>

<p>If this is given then the output of the compiler will be sent directly
to this handle, rather than being buffered in memory. This is an
optimization to avoid memory usage.</p>
</li>
</ul>
</dd>
<dt><strong><A NAME="object_id" class="item">object_id</a></strong></dt>

<dd>
<p>This method should return a unique id for the given compiler object.
This is used by the interpreter when determining the object directory,
for example.</p>
</dd>
</dl>
<p>
</p>
<h2><A NAME="compilation_callbacks">Compilation Callbacks</a></h2>
<p>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.</p>
<dl>
<dt><strong><A NAME="start_component" class="item"><code>start_component()</code></a></strong></dt>

<dd>
<p>This method is called by the Lexer when it starts processing a
component.</p>
</dd>
<dt><strong><A NAME="end_component" class="item"><code>end_component()</code></a></strong></dt>

<dd>
<p>This method is called by the Lexer when it finishes processing a
component.</p>
</dd>
<dt><strong><A NAME="start_block" class="item">start_block(block_type =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>This method is called by the Lexer when it encounters an opening Mason
block tag like <code>&lt;%perl&gt;</code> or <code>&lt;%args&gt;</code>.  Its main purpose is
to keep track of the nesting of different kinds of blocks within each
other.  The type of block (&quot;init&quot;, &quot;once&quot;, etc.) is passed via the
&quot;block_type&quot; parameter.</p>
</dd>
<dt><strong><A NAME="end_block" class="item">end_block(block_type =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>This method is called by the Lexer when it encounters a closing Mason
block tag like <code>&lt;/%perl&gt;</code> or <code>&lt;/%args&gt;</code>.  Like
<A HREF="#start_block"><code>start_block()</code></a>, its main purpose is to help maintain syntactic
integrity.</p>
</li>
<li>
<p>Several compiler methods like <code>doc_block()</code>, <code>text_block()</code>, and
<code>raw_block()</code> are called by the Lexer after <A HREF="#start_block"><code>start_block()</code></a> 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.</p>
<p>The methods that follow this pattern are <code>init_block()</code>,
<code>perl_block()</code>, <code>doc_block()</code>, <code>text_block()</code>, and <code>raw_block()</code>.
The last method is called for all <code>&lt;%once&gt;</code>, <code>&lt;%cleanup&gt;</code>,
<code>&lt;%filter&gt;</code>, <code>&lt;%init&gt;</code>, <code>&lt;%perl&gt;</code>, and <code>&lt;%shared&gt;</code>
blocks.</p>
</dd>
<dt><strong><A NAME="text" class="item">text(text =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>Inserts the text contained in a <A HREF="#text"><code>text</code></a> parameter into the component
for verbatim output.</p>
<p>This is called when the lexer finds plain text in a component.</p>
</dd>
<dt><strong><A NAME="variable_declaration" class="item">variable_declaration( type =&gt; &lt;string&gt;, name =&gt; &lt;string&gt;, default =&gt; &lt;string&gt; )</a></strong></dt>

<dd>
<p>Inserts a variable declaration from the <code>&lt;%args&gt;</code> section into
the component.</p>
<p>The type will be either &quot;$&quot;, &quot;@&quot;, or &quot;%&quot;, indicating a scalar, array,
or hash.  The name is the variable name without the leading sigil.
The default is everything found after the first &quot;=&gt;&quot; on an <code>&lt;%args&gt;</code>
block line, and may include a comment.</p>
</dd>
<dt><strong><A NAME="key_value_pair" class="item">key_value_pair(block_type =&gt; &lt;string&gt;, key =&gt; &lt;string&gt;, value =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>Inserts a key-value pair from a <code>&lt;%flags&gt;</code> or <code>&lt;%attr&gt;</code>
section into the component.</p>
<p>The &quot;block_type&quot; parameter will be either &quot;flags&quot; or &quot;attr&quot;.</p>
</dd>
<dt><strong><A NAME="start_named_block" class="item">start_named_block(block_type =&gt; &lt;string&gt;, name =&gt; &lt;name&gt;)</a></strong></dt>

<dd>
<p>Analogous to <A HREF="#start_block">item_start_block</a>, but starts a &quot;named&quot; block 
(<code>&lt;%method&gt;</code> or <code>&lt;%def&gt;</code>).</p>
</dd>
<dt><strong><A NAME="end_named_block" class="item"><code>end_named_block()</code></a></strong></dt>

<dd>
<p>Called by the Lexer to end a &quot;named&quot; block.</p>
</dd>
<dt><strong><A NAME="substitution" class="item">substitution(substitution =&gt; &lt;string&gt;, escape =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>Called by the Lexer when it encounters a substitution tag 
(<code>&lt;% ... %&gt;</code>).</p>
<p>The value of the &quot;escape&quot; parameter will be everything found after the
pipe (|) in the substitution tag, and may be more than one character
such as &quot;nh&quot;.</p>
</dd>
<dt><strong><A NAME="component_call" class="item">component_call(call =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>Called by the Lexer when it encounters a component call tag without
embedded content (<code>&lt;&amp; ... &amp;&gt;</code>).</p>
<p>The &quot;call&quot; parameter contains the entire contents of the tag.</p>
</dd>
<dt><strong><A NAME="component_content_call" class="item">component_content_call(call =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>Called by the Lexer when it encounters a component call tag with
embedded content (<code>&lt;&amp;| ... &amp;&gt;</code>).</p>
</dd>
<dt><strong><A NAME="component_content_call_end" class="item"><code>component_content_call_end()</code></a></strong></dt>

<dd>
<p>Called by the Lexer when it encounters an ending tag for a component
call with content (<code>&lt;/&amp;&gt;</code>).  Note that there is no corresponding
<code>component_call_end()</code> method for component calls without content,
because these calls don't have ending tags.</p>
</dd>
<dt><strong><A NAME="perl_line" class="item">perl_line(line =&gt; &lt;string&gt;)</a></strong></dt>

<dd>
<p>Called by the Lexer when it encounters a <code>%</code>-line.</p>
</dd>
</dl>
<p>
</p>
<hr />
<h1><A NAME="subclassing">SUBCLASSING</a></h1>
<p>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.</p>
<p>
</p>
<hr />
<h1><A NAME="see_also">SEE ALSO</a></h1>
<p><a HREF="Mason.html">HTML::Mason</a>,
<a HREF="Admin.html">HTML::Mason::Admin</a>,
<a HREF="Interp.html">HTML::Mason::Interp</a></p>

</body>

</html>