MooseX::Templated::View - Interface for MooseX::Templated views
package MooseX::Templated::View::SomeRenderer; use Moose; use Some::Renderer; with 'MooseX::Templated::View'; # engine class has '+engine_class' => ( default => 'Some::Renderer' ); # default config to pass to engine constructor has '+engine_config' => ( default => sub { { OPTION => 1 } } ); # default file extension to use has '+template_src_ext' => ( default => '.ext' ); # return rendered output as string sub process { my $self = shift; # instantiated from engine_class and engine_config my $engine = $self->engine; # source set by framework defaults my $source = $self->source; # implemented by engine my $output = $engine->some_render_method( src => $source, stash => { self => $self }, ); return $output; }
/path/to/Farm/Chicken.pm
package Farm::Chicken; use Moose; with 'MooseX::Templated::Role'; has 'feathers' => ( is => 'rw' );
/path/to/Farm/Chicken.ext
This chicken has <<self.feathers>> feathers
Elsewhere...
$chicken = Farm::Chicken->new( feathers => 57, template_view_class => 'MooseX::Templated::View::SomeRenderer', ); $chicken->render(); # This chicken has 57 feathers
Instance of the templating engine used for the render
The class name of template engine object
This is used to instantiate the new
Configuration options to pass to the Template engine constructor
This is a reference to the object we are rendering - i.e. the object consuming the MooseX::Templated::Role
This is the template source string
Where to start looking for associated template files. If this evaluates to false then it will assume the template file resides alongside the module (with a different extension depending on the particular view).
Farm::Cow.pm template_src_base => '' # /usr/lib/perl5/[...]/Farm/Cow.tt template_src_base => '/etc/tt2/src' # /etc/tt2/src/Farm/Cow.tt
Extension to use when searching for the template_src, e.g. '.tt'
This sets up the generic environment for the render (e.g. template source and stash vars) then calls the process method on the implementing view.
Sets the template source to something other than the default
See source
Provides additional key/value data to be available in the template source
The individual view implements this method to actually process the template.
Template source code used to process the template - will return the first successful step from the following:
e.g. for MooseX::Templated::View::TT
source => '' # Farm::Cow::_template() # /path/to/Farm/Cow.tt source => 'XML' # Farm::Cow::_template_xml() # /path/to/Farm/Cow.xml.tt source => 'file.tt'
source => \'[% self.blah %]'
Builds the default filename to be used the template source
Farm::Cow => /path/to/Farm/Cow.tt template_src_base class_name template_src_ext /path/to/ Farm/Cow .tt
Explicitly passed options override defaults
This is an interface that allows the front-end MooseX::Templated::Role to speak to the specific back-end template engines (e.g. MooseX::Templated::View::TT). It also provides generic functionality for all MooseX::Templated::View:: modules.
Readonly, File::Slurp, File::Where, Path::Class::File
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.