| App-TemplateServer-Provider-Mason documentation | Contained in the App-TemplateServer-Provider-Mason distribution. |
App::TemplateServer::Provider::Mason - serve Mason templates with App::TemplateServer
Use Mason templates with App::TemplateServer.
template-server --provider Mason --docroot /mason/templates
See template-server and <App::TemplateServer> for details.
Jonathan Rockway <jrockway@cpan.org>
This module is Free software, you may redistribute it under the same terms as Perl itself.
| App-TemplateServer-Provider-Mason documentation | Contained in the App-TemplateServer-Provider-Mason distribution. |
package App::TemplateServer::Provider::Mason; use Moose; use Method::Signatures; use File::Find; use HTML::Mason::Interp; use Path::Class qw(file); use feature ':5.10'; our $VERSION = '0.01'; with 'App::TemplateServer::Provider::Filesystem'; method render_template($template, $context){ my $outbuf; my %data = %{$context->data||{}}; my @globals = map { "\$$_" } keys %data; my $interp = HTML::Mason::Interp->new( comp_root => [map {state $a = 1; [$a++ => "$_"]} $self->docroot], out_method => \$outbuf, allow_globals => \@globals, ); # set globals for my $var (keys %data){ my $val = $data{$var}; $interp->set_global($var, $val); } $interp->exec("/$template"); return $outbuf; }; 1; __END__