my $p = new HTML::Mason::Parser (...params...);
$@%
), 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 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 preprocess.
use vars qw($r);
to suppress strict warnings about uses of global $r
(the
Apache request object). See 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.
my $parser = new HTML::Mason::Parser; my $strictmode = $parser->use_strict; $parser->use_strict(1);
The only exception is 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:
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:
# 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);
#!/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');