HTML::Mason::Parser - Mason Component Parser |
new()
CONSTRUCTOR
HTML::Mason::Parser - Mason Component Parser
my $p = new HTML::Mason::Parser (...params...);
A Parser object translates components into Perl subroutines. Parsers are typically embedded within (and used by) Interp objects.
new()
CONSTRUCTORThese parameters affect the way that components are translated into Perl code. If you change a Parser's options, you must remove any previously created object files for the changes to take effect. See also Admin/Object files.
$@%
), 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.
h - escape for HTML ('<' => '<', etc.) u - escape for URL (':' => '%3A', etc.)
The developer can override default escape flags on a per-expression basis; see Devel/escaping_expressions.
ignore_warnings_expr => 'Global symbol.*requires explicit package'
If undef, all warnings are heeded; if '.', all warnings are ignored.
By default, this is set to 'Subroutine .* redefined'. This allows you to declare global subroutines inside <%once> sections and not receive an error when the component is reloaded.
HTML::Mason::Commands
.
This is the ideal place to translate accents into HTML entities. It could also be used to strip out comments that you have in your HTML files that you don't want the end user to see. See Parser/preprocess.
use vars qw($r);
to suppress strict warnings about uses of global $r (the Apache request object). See Parser/postamble.
-T
flag). If true, Mason will pass all
component source and filenames through a dummy regular expression
match to untaint them. In the future this option may become more
sophisticated to allow stricter checks. Default is false.
Most of the above properties have standard accessor methods of the same name: no arguments retrieves the value, and one argument sets it. For example:
my $parser = new HTML::Mason::Parser; my $strictmode = $parser->use_strict; $parser->use_strict(1);
The only exception is Parser/allow_globals, which works a bit differently.
Returns the new Component object on success, or undef if an error occurred. error is an optional scalar reference filled with the error message.
Example of usage:
# Make a component my $comp = $parser->make_component (script=>'<%perl>my $name = "World";</%perl>Hello <% $name %>!', error => \my $error) or die "error while compiling component: $error";
# Call it from inside another component $m->comp($comp);
comp_root and data_dir contain the Mason component root and data directory respectively. These are required.
paths is a reference to a list of component paths to make recursively. By default, makes '/' (the entire component tree).
verbose is a flag indicating whether to report components compiled and directories created. True by default.
predicate is a subroutine that takes one argument, the component source file, and returns true or false indicating whether or not to try to compile it. By default predicate ignores all filenames ending with ``~''.
dir_create_mode contains the permissions mode for creating new directories, by default 0775.
update_reload_file is a flag indicating whether to update a reload file in the data directory as components are recompiled. False by default.
Example of usage:
#!/usr/bin/perl use HTML::Mason; use HTML::Mason::ApacheHandler; # load explicitly to bring in special $m-> commands
my $p = new HTML::Mason::Parser; $p->allow_globals(qw($r)); # allow Apache $r global $p->make_dirs (comp_root=>'/usr/home/swartz/web/comps', data_dir=>'/usr/home/swartz/web/mason');
Jonathan Swartz, swartz@pobox.com
HTML::Mason, HTML::Mason::Interp, HTML::Mason::ApacheHandler, HTML::Mason::Admin
HTML::Mason::Parser - Mason Component Parser |