| 1 | package Dancer::Template::MojoTemplate; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Mojo::Template wrapper for Dancer | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Mojo::Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use base 'Dancer::Template::Abstract'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | my $_engine; | |||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub default_tmpl_ext { "ep" }; | ||||||||
|
Subroutine
default_tmpl_ext: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub init { | ||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 16 | 0 | my $self = shift; | |||||||||
| 17 | |||||||||||
| 18 | my %args = ( | ||||||||||
| 19 | 0 | %{$self->config}, | |||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 0 | $_engine = Mojo::Template->new(%args); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub render { | ||||||||
|
Subroutine
render: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 26 | 0 | my ($self, $template, $tokens) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my $content = eval { | |||||||||
| 29 | 0 | $_engine->render_file($template, $tokens) | |||||||||
| 30 | }; | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | die qq{Couldn't render template: $@}; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | return $content; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | 1; | |||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | =pod | ||||||||||
| 43 | |||||||||||
| 44 | =head1 NAME | ||||||||||
| 45 | |||||||||||
| 46 | Dancer::Template::MojoTemplate - Mojo::Template wrapper for Dancer | ||||||||||
| 47 | |||||||||||
| 48 | =head1 VERSION | ||||||||||
| 49 | |||||||||||
| 50 | version 0.2.0 | ||||||||||
| 51 | |||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||
| 53 | |||||||||||
| 54 | This is an interface between Dancer's template engine abstraction layer and | ||||||||||
| 55 | the L<Mojo::Template> module. | ||||||||||
| 56 | |||||||||||
| 57 | In order to use this engine, use the template setting: | ||||||||||
| 58 | |||||||||||
| 59 | template: mojo_template | ||||||||||
| 60 | |||||||||||
| 61 | This can be done in your config.yml file or directly in your app code with | ||||||||||
| 62 | the B<set> keyword. | ||||||||||
| 63 | |||||||||||
| 64 | You can configure L<Mojo::Template> : | ||||||||||
| 65 | |||||||||||
| 66 | template: 'mojo_template' | ||||||||||
| 67 | engines: | ||||||||||
| 68 | mojo_template: | ||||||||||
| 69 | auto_escape: 1 | ||||||||||
| 70 | trim_mark: '-' | ||||||||||
| 71 | prepend: 'my $t = $_[0];' | ||||||||||
| 72 | |||||||||||
| 73 | =head1 SEE ALSO | ||||||||||
| 74 | |||||||||||
| 75 | L<Dancer>, L<Mojo::Template>, L<http://mojolicio.us/> | ||||||||||
| 76 | |||||||||||
| 77 | =head1 AUTHOR | ||||||||||
| 78 | |||||||||||
| 79 | James Aitken <jaitken@cpan.org> | ||||||||||
| 80 | |||||||||||
| 81 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 82 | |||||||||||
| 83 | This software is copyright (c) 2011 by James Aitken. | ||||||||||
| 84 | |||||||||||
| 85 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 86 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||