Text::MicroMason::Base - Simple Compiler for Mason Templating
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');
The Text::MicroMason::Base class provides a parser and execution environment for a simple templating system based on HTML::Mason.
The template syntax supported by Text::MicroMason and some useful template developer techniques are described in Text::MicroMason::Devel.
$mason = $class->new( %options ); $clone = $mason->new( %options );
Creates a new instance with the provided key value pairs.
$code_ref = $mason->compile( text => $template, %options ); $code_ref = $mason->compile( file => $filename, %options );
Parses the provided template and converts it into a new Perl subroutine.
$result = $mason->execute( text => $template, @arguments ); $result = $mason->execute( file => $filename, @arguments ); $result = $mason->execute( code => $code_ref, @arguments ); $result = $mason->execute( $type => $source, \%options, @arguments );
Returns the results produced by the template, given the provided arguments.
The following internal methods are used to implement the public interface described above, and may be overridden by subclasses and mixins.
This class method is called by new() to provide key-value pairs to be included in the new instance.
@tokens = $mason->lex( $template );
Parses the provided template text and returns a list of token types and values.
$perl_code = $mason->assemble( @tokens );
Assembles the parsed token series into the source code for the equivalent Perl subroutine.
Called by assemble(), this method provides support for Mason's <%args> blocks.
$code_ref = $mason->eval_sub( $perl_code );
Compiles the Perl source code for a template using eval(), and returns a code reference.
( $type, $data ) = $mason->resolve( $type, $data );
Called by compile(), the resolve method allows the template source type and value arguments to be normalized or resolved in various ways before the template is read using one of the read_type() methods.
$template = $mason->read_text( $template );
Called by compile() when the template source type is "text", this method simply returns the value of the text string passed to it.
( $contents, %path_info ) = $mason->read_file( $filename );
Called by compile() when the template source type is "file", this method reads and returns the contents of the named file.
Called to provide a debugging message for developer reference. No output is produced unless the object's 'debug' flag is true.
Called when a fatal exception has occured.
$special_characters_escaped = _printable( $source_string );
Converts non-printable characters to readable form using the standard backslash notation, such as "\n" for newline.
Boolean value. Debugging flag activates warns throughout the code. Used by debug_msg().
Reference to a hash of text elements used for Perl subroutine assembly. Used by assemble().
The assembly template defines the types of blocks supported and the order they appear in, as well as where other standard elements should go. Those other elements also appear in the assembler hash.
For a full-featured web application system using this template syntax, see HTML::Mason.
For distribution, installation, support, copyright and license information, see Text::MicroMason::ReadMe.
To install Text::MicroMason, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::MicroMason
CPAN shell
perl -MCPAN -e shell install Text::MicroMason
For more information on module installation, please visit the detailed CPAN module installation guide.