MooseX::Templated::Engine - connects MooseX::Templated object to template
Internal docs - see MooseX::Templated for usage.
my $engine = MooseX::Templated::Engine->new( model => My::Module->new( ... ), view_class => 'MooseX::Templated::View::TT', view_config => \%config, template_suffix => '.tt', template_root => '__LIB__/root/src', template_method_stub => '_template', ); $engine->render(); # source: # @INC/root/src/My/Module.tt # My::Module::_template $engine->render( source => "xml" ); # source: # @INC/root/src/My/Module.xml.tt # My::Module::_template_xml $engine->render( source => "/path/to/file.ext" ); # source: # /path/to/file.ext $engine->render( source => \"[% template %]" ); # source: # <inline>
A shortcut is a simple string such as "xml".
"xml"
Called from the module Farm::Cow, this will attempt to find the file:
Farm::Cow
@INC/Farm/Cow.xml.tt
based on:
${template_root}/Farm/Cow.${shortcut}.${template_suffix}
Otherwise it will check with the calling object has a method:
Farm::Cow::_template_xml
Builds the default filename to be used the template source
Farm::Cow => /path/to/Farm/Cow.tt template_root class_name template_suffix /path/to/ Farm/Cow .tt
Explicitly passed options override defaults
This renders the module consuming this role and returns the output as a string. This method accepts the following optional key/values (either as %options or \%options):
Specifies the template source to be used for the rendering process. For flexibility, the source can be specified in a number of different ways - the intention is for it to Do What You Mean (DWYM).
How the source is interpreted will depend partly on the default options specified by the template_view_class that you are using (the default view is MooseX::Templated::View::TT). However, for consistency across your application, the recommended usage is to allow the template source to be decided by using 'shortcuts'.
Default:
Farm::Cow->new->render() # CHECKS FOR: # - Farm::Cow::_template() # - /path/to/Farm/Cow.tt
Using shortcuts:
Farm::Cow->new->render( source => 'xml' ) # CHECKS FOR: # - Farm::Cow::_template_xml() # - /path/to/Farm/Cow.xml.tt
These alternatives will also work:
Farm::Cow->new->render( source => '/other/path/cow.tt' ); Farm::Cow->new->render( source => \'Cow goes [% self.moo %]' );
See "Setting the template source" for more information on the logic behind choosing how to interpret this string.
Provides access to the underlying MooseX::Templated::View object
Can be passed in the constructor to specify which MooseX::Templated::View to use.
By default this is set to use the view based on Template Toolkit:
'view_class' => 'MooseX::Templated::View::TT'
However, it is entirely possible that views will be written for different templating engines in the future (contribs welcome!).
See MooseX::Templated::View for details on implementing your own view.
Config options to be passed to the template view class when creating the template engine. These will be merged with any default parameters set by the view engine.
Moose, Template, Readonly, File::Slurp
None reported.
No bugs have been reported.
Please report any bugs or feature requests to bug-moosex-templated@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-moosex-templated@rt.cpan.org
Chris Prather (perigrin)
Ian Sillitoe <isillitoe@cpan.org>
<isillitoe@cpan.org>
Copyright (c) 2008, Ian Sillitoe <isillitoe@cpan.org>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install MooseX::Templated, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Templated
CPAN shell
perl -MCPAN -e shell install MooseX::Templated
For more information on module installation, please visit the detailed CPAN module installation guide.