NAME
Text::MicroMason::Mason - Simple Compiler for Mason-style Templating
SYNOPSIS
Create a Mason object to interpret the templates:
use Text::MicroMason;
my $mason = Text::MicroMason->new();
Use the execute method to parse and evalute a template:
print $mason->execute( text=>$template, 'name'=>'Dave' );
Or compile it into a subroutine, and evaluate repeatedly:
$coderef = $mason->compile( text=>$template );
print $coderef->('name'=>'Dave');
print $coderef->('name'=>'Bob');
Templates stored in files can be run directly or included in others:
print $mason->execute( file=>"./greeting.msn", 'name'=>'Charles');
DESCRIPTION
The Text::MicroMason::Mason class provides lexer and assembler methods that allow Text::MicroMason to handle most elements of HTML::Mason's template syntax.
Template Syntax
The template syntax supported by Text::MicroMason and some useful template developer techniques are described in Text::MicroMason::Devel.
Compatibility with HTML::Mason
HTML::Mason is a full-featured application server toolkit with many fatures, of which only the templating functionality is emulated.
The following sets of HTML::Mason features are supported by Text::MicroMason:
Template interpolation with <% expr %>
Literal Perl lines with leading %
Named %args, %perl, %once, %init, %cleanup, and %doc blocks
The $m mason object, although with many fewer methods
Expression filtering with |h and |u (via -Filter mixin)
The following sets of HTML::Mason features are not supported by Text::MicroMason:
No %attr, %shared, %method, or %def blocks.
No $r request object.
No shared files like autohandler and dhandler.
No mod_perl integration or configuration capability.
Contributed patches to add these features of HTML::Mason would be welcomed by the author.
Private Methods
The following internal methods are used to implement the public interface described above, and may be overridden by subclasses and mixins.
- lex_token
-
( $type, $value ) = $mason->lex_token();
Supports HTML::Mason's markup syntax.
Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error.
- assembler_rules()
-
Returns a hash of text elements used for Perl subroutine assembly. Used by assemble().
Supports HTML::Mason's named blocks of Perl code and documentation: %once, %init, %cleanup, and %doc.
- assemble_args
-
Called by assemble(), this method provides support for Mason's <%args> blocks.
SEE ALSO
For a full-featured web application system using this template syntax, see HTML::Mason.
For an overview of this distribution, see Text::MicroMason.
This is a subclass intended for use with Text::MicroMason::Base.
For distribution, installation, support, copyright and license information, see Text::MicroMason::ReadMe.