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.
ignore_warnings_expr => 'Global symbol.*requires explicit package'
Undefined by default, meaning that all warnings are fatal.
HTML::Mason::Commands
.
You will have to explicitly import the mc_* commands from HTML::Mason::Commands
into your package. Ideally you will put this in your handler.pl
:
{ package MyPackage; use HTML::Mason::Commands; }
This will bring in all of the mc_ commands. If you want to save some space on imported symbols, specify just the commands you want:
{ package MyPackage; use HTML::Mason::Commands qw(mc_comp mc_file mc_cache); }
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.
% my $noun = "World"; Hello, <% $noun %>! How are ya?
Has 51 total bytes, 19 of which are plain text. This allows you to adjust the trade-off between the memory savings of source references and the performance advantage of in-line plain text. For example, to choose only components with at least 50% plain text:
source_refer_predicate => sub { return $_[1] / $_[0] >= 0.5 }
The current default is
sub { return $_[1] >= 500 }
i.e. any component with at least 500 characters. This is an experimental setting and may change.
-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.
The component may be passed in as a string in script, or as a filename in script_file.
The subroutine can be output in three ways. result_text is an optional scalar reference; if specified, it is filled with a Perl
script that, when evaluated, returns the new subroutine. result_code is an optional code reference filled with the new subroutine itself. save_to is an optional filename for an object file.
The method returns 1 on success and 0 if there was an error. error
is an optional scalar reference filled with any parsing or compilation
errors that occur. Alternatively, if the wrap_errors flag is set to true, then any errors that occur are simply wrapped up to be
displayed by the subroutine -- in this case the method always ``succeeds''
and returns 1.
pure_text_flag is an optional scalar reference filled with a flag indicating whether the
component was pure text (free of Mason syntax).
Here's an example that creates an object file from a component source file:
$parser->parse(script_file => '/usr/www/docs/template',
save_to => '/usr/www/data/obj/template',
error => \$error)
or die "error while compiling component: $error";