DOKK / manpages / debian 11 / libtext-micromason-perl / Text::MicroMason::AllowGlobals.3pm.en
Text::MicroMason::AllowGlobals(3pm) User Contributed Perl Documentation Text::MicroMason::AllowGlobals(3pm)

Text::MicroMason::AllowGlobals - Share package vars between templates

Instead of using this class directly, pass its name to be mixed in:

    use Text::MicroMason;
    my $mason = Text::MicroMason->new( -AllowGlobals );

Share package variables:

    $mason->set_globals( '$name' => 'Bob' );

Use the standard compile and execute methods to parse and evaluate templates:

  print $mason->compile( text=>$template )->();
  print $mason->execute( text=>$template );

Then, in a template, you can refer to those globals:

    Welcome, <% $name %>!

Accepts a list of pairs of global variable names and corresponding values.

Adds each variable name to the allowed list and sets it to the initial value.

Gets or sets the variables names to be allowed.

If called with arguments, adds them to the list.

Returns the variables to be allowed as a list, or as a space-separated string in scalar context.

Optional array or space-separated string of global variable names to be allowed.

Adds the allow_globals_statement to each token stream before assembling it.
This method prepends the "use vars" statement needed for the template subroutines to compile.

For an overview of this templating framework, see Text::MicroMason.

This is a mixin class intended for use with Text::MicroMason::HTMLMason.

For distribution, installation, support, copyright and license information, see Text::MicroMason::Docs::ReadMe.

2019-11-10 perl v5.30.0