1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
<?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">
<p><A NAME="__index__"></a></p>
<!-- INDEX BEGIN -->
<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>
<!-- INDEX END -->
<hr />
<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="item_allow_globals">allow_globals</a></strong>
<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 ``use vars'' statement. For example:</p>
</dd>
<dd>
<pre>
allow_globals => [qw($DBH %session)]</pre>
</dd>
<dd>
<p>In a mod_perl environment, <code>$r</code> (the request object) is automatically
added to this list.</p>
</dd>
</li>
<dt><strong><A NAME="item_default_escape_flags">default_escape_flags</a></strong>
<dd>
<p>Escape flags to apply to all <% %> expressions by default. The current
valid flags are</p>
</dd>
<dd>
<pre>
h - escape for HTML ('<' => '&lt;', etc.)
u - escape for URL (':' => '%3A', etc.)</pre>
</dd>
<dd>
<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>
</dd>
<dd>
<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>
</li>
<dt><strong><A NAME="item_enable_autoflush">enable_autoflush</a></strong>
<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>
</li>
<dt><strong><A NAME="item_lexer">lexer</a></strong>
<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>
</li>
<dt><strong><A NAME="item_lexer_class">lexer_class</a></strong>
<dd>
<p>The class to use when creating a lexer. Defaults to <a HREF="Lexer.html">HTML::Mason::Lexer</a>.</p>
</dd>
</li>
<dt><strong><A NAME="item_preprocess">preprocess</a></strong>
<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>
</li>
<dt><strong><A NAME="item_postprocess_text">postprocess_text</a></strong>
<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>
</li>
<dt><strong><A NAME="item_postprocess_perl">postprocess_perl</a></strong>
<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>
</li>
<dt><strong><A NAME="item_use_source_line_numbers">use_source_line_numbers</a></strong>
<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>
</li>
</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="item_compile">compile(comp_source => <string>, name => <string>, comp_class => <string>)</a></strong>
<dd>
<p>The ``comp_class'' parameter may be ignored by the compiler.</p>
</dd>
</li>
<dt><strong><A NAME="item_object_id">object_id</a></strong>
<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>
</li>
</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="item_start_component"><code>start_component()</code></a></strong>
<dd>
<p>This method is called by the Lexer when it starts processing a
component.</p>
</dd>
</li>
<dt><strong><A NAME="item_end_component"><code>end_component()</code></a></strong>
<dd>
<p>This method is called by the Lexer when it finishes processing a
component.</p>
</dd>
</li>
<dt><strong><A NAME="item_start_block">start_block(block_type => <string>)</a></strong>
<dd>
<p>This method is called by the Lexer when it encounters an opening Mason
block tag like <code><%perl></code> or <code><%args></code>. 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.</p>
</dd>
</li>
<dt><strong><A NAME="item_end_block">end_block(block_type => <string>)</a></strong>
<dd>
<p>This method is called by the Lexer when it encounters a closing Mason
block tag like <code></%perl></code> or <code></%args></code>. Like
<A HREF="#item_start_block"><code>start_block()</code></a>, its main purpose is to help maintain syntactic
integrity.</p>
</dd>
</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="#item_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><%once></code>, <code><%cleanup></code>,
<code><%filter></code>, <code><%init></code>, <code><%perl></code>, and <code><%shared></code>
blocks.</p>
</li>
<dt><strong><A NAME="item_text">text(text => <string>)</a></strong>
<dd>
<p>Inserts the text contained in a <A HREF="#item_text"><code>text</code></a> parameter into the component
for verbatim output.</p>
</dd>
<dd>
<p>This is called when the lexer finds plain text in a component.</p>
</dd>
</li>
<dt><strong><A NAME="item_variable_declaration">variable_declaration( type => <string>, name => <string>, default => <string> )</a></strong>
<dd>
<p>Inserts a variable declaration from the <code><%args></code> section into
the component.</p>
</dd>
<dd>
<p>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 <code><%args></code>
block line, and may include a comment.</p>
</dd>
</li>
<dt><strong><A NAME="item_key_value_pair">key_value_pair(block_type => <string>, key => <string>, value => <string>)</a></strong>
<dd>
<p>Inserts a key-value pair from a <code><%flags></code> or <code><%attr></code>
section into the component.</p>
</dd>
<dd>
<p>The ``block_type'' parameter will be either ``flags'' or ``attr''.</p>
</dd>
</li>
<dt><strong><A NAME="item_start_named_block">start_named_block(block_type => <string>, name => <name>)</a></strong>
<dd>
<p>Analogous to <A HREF="#item_start_block">item_start_block</a>, but starts a ``named'' block
(<code><%method></code> or <code><%def></code>).</p>
</dd>
</li>
<dt><strong><A NAME="item_end_named_block"><code>end_named_block()</code></a></strong>
<dd>
<p>Called by the Lexer to end a ``named'' block.</p>
</dd>
</li>
<dt><strong><A NAME="item_substitution">substitution(substitution => <string>, escape => <string>)</a></strong>
<dd>
<p>Called by the Lexer when it encounters a substitution tag
(<code><% ... %></code>).</p>
</dd>
<dd>
<p>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''.</p>
</dd>
</li>
<dt><strong><A NAME="item_component_call">component_call(call => <string>)</a></strong>
<dd>
<p>Called by the Lexer when it encounters a component call tag without
embedded content (<code><& ... &></code>).</p>
</dd>
<dd>
<p>The ``call'' parameter contains the entire contents of the tag.</p>
</dd>
</li>
<dt><strong><A NAME="item_component_content_call">component_content_call(call => <string>)</a></strong>
<dd>
<p>Called by the Lexer when it encounters a component call tag with
embedded content (<code><&| ... &></code>).</p>
</dd>
</li>
<dt><strong><A NAME="item_component_content_call_end"><code>component_content_call_end()</code></a></strong>
<dd>
<p>Called by the Lexer when it encounters an ending tag for a component
call with content (<code></&></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>
</li>
<dt><strong><A NAME="item_perl_line">perl_line(line => <string>)</a></strong>
<dd>
<p>Called by the Lexer when it encounters a <code>%</code>-line.</p>
</dd>
</li>
</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>
|