Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > b19212d1d821b5016fd913fedcadbd3c > files > 75

mason-1.420.0-1mdv2010.0.noarch.rpm

<?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::Interp - Mason Component Interpreter</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="#escape_flag_methods">ESCAPE FLAG METHODS</a></li>
	<li><A HREF="#other_methods">OTHER METHODS</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::Interp - Mason Component Interpreter</p>
<p>
</p>
<hr />
<h1><A NAME="synopsis">SYNOPSIS</a></h1>
<pre>
    my $i = HTML::Mason::Interp-&gt;new (data_dir=&gt;'/usr/local/mason',
                                      comp_root=&gt;'/usr/local/www/htdocs/',
                                      ...other params...);</pre>
<p>
</p>
<hr />
<h1><A NAME="description">DESCRIPTION</a></h1>
<p>Interp is the Mason workhorse, executing components and routing their
output and errors to all the right places. In a mod_perl environment,
Interp objects are handed off immediately to an ApacheHandler object
which internally calls the Interp implementation methods. In that case
the only user method is the <code>new()</code> constructor.</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="autohandler_name" class="item">autohandler_name</a></strong></dt>

<dd>
<p>File name used for
<A HREF="Devel.html#autohandlers">autohandlers</a>. Default is
&quot;autohandler&quot;.  If this is set to an empty string (&quot;&quot;) then
autohandlers are turned off entirely.</p>
</dd>
<dt><strong><A NAME="buffer_preallocate_size" class="item">buffer_preallocate_size</a></strong></dt>

<A NAME="item_buffer_preallocate_size"></a><dd>
<p>Number of bytes to preallocate in the output buffer for each request.
Defaults to 0. Setting this to, say, your maximum page size (or close
to it) can reduce the number of reallocations Perl performs as
components add to the output buffer.</p>
</dd>
<dt><strong><A NAME="code_cache_max_size" class="item">code_cache_max_size</a></strong></dt>

<A NAME="item_code_cache_max_size"></a><dd>
<p>Specifies the maximum number of components that should be held in the
in-memory code cache. The default is 'unlimited', meaning no
components will ever be discarded; Mason can perform certain
optimizations in this mode. Setting this to zero disables the code
cache entirely. See the <A HREF="Admin.html#code_cache">code cache</a>
section of the administrator's manual for further details.</p>
</dd>
<dt><strong><A NAME="comp_root" class="item">comp_root</a></strong></dt>

<A NAME="item_comp_root"></a><dd>
<p>The component root marks the top of your component hierarchy and
defines how component paths are translated into real file paths. For
example, if your component root is <em class="file">/usr/local/httpd/docs</em>, a component
path of <em class="file">/products/index.html</em> translates to the file
<em class="file">/usr/local/httpd/docs/products/index.html</em>.</p>
<p>Under <a HREF="ApacheHandler.html">Apache</a> and
<a HREF="CGIHandler.html">CGI</a>, comp_root defaults to the server's
document root. In standalone mode comp_root defaults to the current
working directory.</p>
<p>This parameter may be either a scalar or an array reference.  If it is
a scalar, it should be a filesystem path indicating the component
root. If it is an array reference, it should be of the following form:</p>
<pre>
 [ [ foo =&gt; '/usr/local/foo' ],
   [ bar =&gt; '/usr/local/bar' ] ]</pre>
<p>This is an array of two-element array references, not a hash.  The
&quot;keys&quot; for each path must be unique and their &quot;values&quot; must be
filesystem paths.  These paths will be searched in the provided order
whenever a component path is resolved. For example, given the above
component roots and a component path of <em class="file">/products/index.html</em>, Mason
would search first for <em class="file">/usr/local/foo/products/index.html</em>, then for
<em class="file">/usr/local/bar/products/index.html</em>.</p>
<p>The keys are used in several ways. They help to distinguish component
caches and object files between different component roots, and they
appear in the <code>title()</code> of a component.</p>
<p>When you specify a single path for a component root, this is actually
translated into</p>
<pre>
  [ [ MAIN =&gt; path ] ]</pre>
<p>If you have turned on <A HREF="Params.html#dynamic_comp_root">dynamic_comp_root</a>, you may modify the
component root(s) of an interpreter between requests by calling
<A HREF="#comp_root"><code>$interp-&gt;comp_root</code></a> with a value. However, the path associated
with any given key may not change between requests. For example,
if the initial component root is</p>
<pre>
 [ [ foo =&gt; '/usr/local/foo' ],
   [ bar =&gt; '/usr/local/bar' ], ]</pre>
<p>then it may not be changed to</p>
<pre>
 [ [ foo =&gt; '/usr/local/bar' ],
   [ bar =&gt; '/usr/local/baz' ],</pre>
<p>but it may be changed to</p>
<pre>
 [ [ foo   =&gt; '/usr/local/foo' ],
   [ blarg =&gt; '/usr/local/blarg' ] ]</pre>
<p>In other words, you may add or remove key/path pairs but not modify an
already-used key/path pair. The reason for this restriction is that
the interpreter maintains a component cache per key that would become
invalid if the associated paths were to change.</p>
</dd>
<dt><strong><A NAME="compiler" class="item">compiler</a></strong></dt>

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

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

<dd>
<p>The data directory is a writable directory that Mason uses for various
features and optimizations: for example, component object files and
data cache files. Mason will create the directory on startup, if necessary, and set its
permissions according to the web server User/Group.</p>
<p>Under <a HREF="ApacheHandler.html">Apache</a>, data_dir defaults to a
directory called &quot;mason&quot; under the Apache server root. You will
need to change this on certain systems that assign a high-level
server root such as <em class="file">/usr</em>!</p>
<p>In non-Apache environments, data_dir has no default. If it is left
unspecified, Mason will not use <A HREF="Admin.html#object_files">object files</a>, and the default
<A HREF="Request.html#item_cache">data cache class</a> will be
<code>MemoryCache</code> instead of <code>FileCache</code>.</p>
</dd>
<dt><strong><A NAME="dynamic_comp_root" class="item">dynamic_comp_root</a></strong></dt>

<dd>
<p>True or false, defaults to false. Indicates whether the <A HREF="Params.html#comp_root">comp_root</a>
can be modified on this interpreter between requests. Mason can
perform a few optimizations with a fixed component root, so you
should only set this to true if you actually need it.</p>
</dd>
<dt><strong><A NAME="escape_flags" class="item">escape_flags</a></strong></dt>

<dd>
<p>A hash reference of escape flags to set for this object.  See the
section on the <A HREF="Interp.html#item_set_escape">set_escape method</a> for more details.</p>
</dd>
<dt><strong><A NAME="ignore_warnings_expr" class="item">ignore_warnings_expr</a></strong></dt>

<dd>
<p>Regular expression indicating which warnings to ignore when loading
components. Any warning that is not ignored will prevent the
component from being loaded and executed. For example:</p>
<pre>
    ignore_warnings_expr =&gt;
        'Global symbol.*requires explicit package'</pre>
<p>If set to undef, all warnings are heeded. If set to '.', warnings
are turned off completely as a specially optimized case.</p>
<p>By default, this is set to 'Subroutine .* redefined'.  This allows you
to declare global subroutines inside &lt;%once&gt; sections and not receive
an error when the component is reloaded.</p>
</dd>
<dt><strong><A NAME="object_file_extension" class="item">object_file_extension</a></strong></dt>

<dd>
<p>Extension to add to the end of object files. Default is &quot;.obj&quot;.</p>
</dd>
<dt><strong><A NAME="preloads" class="item">preloads</a></strong></dt>

<dd>
<p>A list of component paths, optionally with glob wildcards, to load
when the interpreter initializes. e.g.</p>
<pre>
    preloads =&gt; ['/foo/index.html','/bar/*.pl']</pre>
<p>Default is the empty list.  For maximum performance, this should only
be used for components that are frequently viewed and rarely updated.
See the <A HREF="Admin.html#preloading_components">preloading components</a> section of the administrator's manual for further details.</p>
<p>As mentioned in the developer's manual, a component's <code>&lt;%once&gt;</code>
section is executed when it is loaded.  For preloaded components, this
means that this section will be executed before a Mason or Apache
request exist, so preloading a component that uses <code>$m</code> or <code>$r</code> in a
<code>&lt;%once&gt;</code> section will fail.</p>
</dd>
<dt><strong><A NAME="request_class" class="item">request_class</a></strong></dt>

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

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

<dd>
<p>The class to use when creating a resolver. Defaults to
<a HREF="Resolver/File.html">HTML::Mason::Resolver::File</a>.</p>
</dd>
<dt><strong><A NAME="static_source" class="item">static_source</a></strong></dt>

<dd>
<p>True or false, default is false. When false, Mason checks the
timestamp of the component source file each time the component is used
to see if it has changed. This provides the instant feedback for
source changes that is expected for development.  However it does
entail a file stat for each component executed.</p>
<p>When true, Mason assumes that the component source tree is unchanging:
it will not check component source files to determine if the memory
cache or object file has expired.  This can save many file stats per
request. However, in order to get Mason to recognize a component
source change, you must flush the memory cache and remove object files.
See <A HREF="Params.html#static_source_touch_file">static_source_touch_file</a> for one easy way to arrange this.</p>
<p>We recommend turning this mode on in your production sites if
possible, if performance is of any concern.</p>
</dd>
<dt><strong><A NAME="static_source_touch_file" class="item">static_source_touch_file</a></strong></dt>

<dd>
<p>Specifies a filename that Mason will check once at the beginning of
of every request. When the file timestamp changes, Mason will (1) clear
its in-memory component cache, and (2) remove object files if
they have not already been deleted by another process.</p>
<p>This provides a convenient way to implement <A HREF="Params.html#static_source">static_source</a> mode.
All you need to do is make sure that a single file gets touched
whenever components change. For Mason's part, checking a single
file at the beginning of a request is much cheaper than checking
every component file when static_source=0.</p>
</dd>
<dt><strong><A NAME="use_object_files" class="item">use_object_files</a></strong></dt>

<dd>
<p>True or false, default is true.  Specifies whether Mason creates
object files to save the results of component parsing. You may want to
turn off object files for disk space reasons, but otherwise this
should be left alone.</p>
</dd>
</dl>
<p>
</p>
<hr />
<h1><A NAME="accessor_methods">ACCESSOR METHODS</a></h1>
<p>All of the above properties have standard accessor methods of the same
name. Only comp_root and ignore_warnings_expr can be modified in an
existing interpreter; the rest are read-only.</p>
<p>
</p>
<hr />
<h1><A NAME="escape_flag_methods">ESCAPE FLAG METHODS</a></h1>
<dl>
<dt><strong><A NAME="apply_escapes" class="item">apply_escapes ($text, $flags, [more flags...])</a></strong></dt>

<A NAME="item_apply_escapes"></a><dd>
<p>This method applies a one or more escapes to a piece of text.  The
escapes are specified by giving their flag.  Each escape is applied to
the text in turn, after which the now-modified text is returned.</p>
</dd>
<dt><strong><A NAME="remove_escape" class="item">remove_escape ($name)</a></strong></dt>

<A NAME="item_remove_escape"></a><dd>
<p>Given an escape name, this removes that escape from the interpreter's
known escapes.  If the name is not recognized, it is simply ignored.</p>
</dd>
<dt><strong><A NAME="set_escape" class="item">set_escape ($name =&gt; see below])</a></strong></dt>

<A NAME="item_set_escape"></a><dd>
<p>This method is called to add an escape flag to the list of known
escapes for the interpreter.  The flag may only consist of the
characters matching <code>\w</code> and the dash (-).  It must start with an
alpha character or an underscore (_).</p>
<p>The right hand side may be one of several things.  It can be a
subroutine reference.  It can also be a string match <code>/^\w+$/</code>, in
which case it is assumed to be the name of a subroutine in the
<code>HTML::Mason::Escapes</code> module.  Finally, if it is a string that does
not match the above regex, then it is assumed to be <code>eval</code>able code,
which will return a subroutine reference.</p>
<p>When setting these with <code>PerlSetVar</code> directives in an Apache
configuration file, you can set them like this:</p>
<pre>
  PerlSetVar  MasonEscapeFlags  &quot;h =&gt; \&amp;HTML::Mason::Escapes::basic_html_escape&quot;
  PerlSetVar  MasonEscapeFlags  &quot;flag  =&gt; \&amp;subroutine&quot;
  PerlSetVar  MasonEscapeFlags  &quot;uc    =&gt; sub { ${$_[0]} = uc ${$_[0]}; }&quot;
  PerlAddVar  MasonEscapeFlags  &quot;thing =&gt; other_thing&quot;</pre>
</dd>
</dl>
<p>
</p>
<hr />
<h1><A NAME="other_methods">OTHER METHODS</a></h1>
<dl>
<dt><strong><A NAME="comp_exists" class="item">comp_exists (path)</a></strong></dt>

<A NAME="item_comp_exists"></a><dd>
<p>Given an <em>absolute</em> component path, this method returns a boolean
value indicating whether or not a component exists for that path.</p>
</dd>
<dt><strong><A NAME="exec" class="item">exec (comp, args...)</a></strong></dt>

<A NAME="item_exec"></a><dd>
<p>Creates a new HTML::Mason::Request object for the given <em>comp</em> and
<em>args</em>, and executes it. The return value is the return value of
<em>comp</em>, if any.</p>
<p>This is useful for running Mason outside of a web environment.
See <A HREF="Admin.html#using_mason_from_a_standalone_sc">using Mason from a standalone script in the HTML::Mason::Admin manpage</a>
for examples.</p>
<p>This method isn't generally useful in a mod_perl environment; see
<A HREF="Devel.html#subrequests">subrequests</a> instead.</p>
</dd>
<dt><strong><A NAME="flush_code_cache" class="item">flush_code_cache</a></strong></dt>

<A NAME="flush_code_cache"></a><dd>
<p>Empties the component cache. When using Perl 5.00503 or earlier, you
should call this when finished with an interpreter, in order to remove
circular references that would prevent the interpreter from being
destroyed.</p>
</dd>
<dt><strong><A NAME="load" class="item">load (path)</a></strong></dt>

<A NAME="item_load"></a><dd>
<p>Returns the component object corresponding to an absolute component
<code>path</code>, or undef if none exists. Dies with an error if the component
fails to load because of a syntax error.</p>
</dd>
<dt><strong><A NAME="make_component" class="item">make_component (comp_source =&gt; ... )</a></strong></dt>

<dt><strong>make_component (comp_file =&gt; ... )</strong></dt>

<A NAME="item_make_component"></a><dd>
<p>This method compiles Mason component source code and returns a
Component object.  The source may be passed in as a string in <code>comp_source</code>,
or as a filename in <code>comp_file</code>.  When using <code>comp_file</code>, the
filename is specified as a path on the file system, not as a path
relative to Mason's component root (see 
<A HREF="Request.html#item_fetch_comp">$m-&gt;fetch_comp</a> for that).</p>
<p>If Mason encounters an error during processing, an exception will be thrown.</p>
<p>Example of usage:</p>
<pre>
    # Make an anonymous component
    my $anon_comp =
      eval { $interp-&gt;make_component
               ( comp_source =&gt; '&lt;%perl&gt;my $name = &quot;World&quot;;&lt;/%perl&gt;Hello &lt;% $name %&gt;!' ) };
    die $@ if $@;</pre>
<pre>
    $m-&gt;comp($anon_comp);</pre>
</dd>
<dt><strong><A NAME="make_request" class="item">make_request (@request_params)</a></strong></dt>

<A NAME="item_make_request"></a><dd>
<p>This method creates a Mason request object. The arguments to be passed
are the same as those for the <code>HTML::Mason::Request-&gt;new</code>
constructor or its relevant subclass. This method will likely only be
of interest to those attempting to write new handlers or to subclass
<code>HTML::Mason::Interp</code>.  If you want to create a <em>subrequest</em>, see
<A HREF="Devel.html#subrequests">subrequests</a> instead.</p>
</dd>
<dt><strong><A NAME="purge_code_cache" class="item">purge_code_cache ()</a></strong></dt>

<A NAME="purge_code_cache"></a><dd>
<p>Called during request execution in order to clear out the code
cache. Mainly useful to subclasses that may want to take some custom
action upon clearing the cache.</p>
</dd>
<dt><strong><A NAME="set_global" class="item">set_global ($varname, [values...])</a></strong></dt>

<A NAME="item_set_global"></a><dd>
<p>This method sets a global to be used in components. <code>varname</code> is a
variable name, optionally preceded with a prefix (<code>$</code>, <code>@</code>, or
<code>%</code>); if the prefix is omitted then <code>$</code> is assumed. <code>varname</code> is
followed by a value, in the case of a scalar, or by one or more values
in the case of a list or hash.  For example:</p>
<pre>
    # Set a global variable $dbh containing the database handle
    $interp-&gt;set_global(dbh =&gt; DBI-&gt;connect(...));</pre>
<pre>
    # Set a global hash %session from a local hash
    $interp-&gt;set_global('%session', %s);</pre>
<p>The global is set in the package that components run in: usually
<code>HTML::Mason::Commands</code>, although this can be overridden via the
<A HREF="Params.html#in_package">in_package</a> parameter.
The lines above, for example, are equivalent to:</p>
<pre>
    $HTML::Mason::Commands::dbh = DBI-&gt;connect(...);
    %HTML::Mason::Commands::session = %s;</pre>
<p>assuming that <A HREF="Params.html#in_package">in_package</a> has not been changed.</p>
<p>Any global that you set should also be registered with the
<A HREF="Params.html#allow_globals">allow_globals</a> parameter; otherwise you'll get warnings from
<code>strict</code>.</p>
</dd>
</dl>
<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="ApacheHandler.html">HTML::Mason::ApacheHandler</a></p>

</body>

</html>