blib/lib/Dancer/Template/Mustache.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 90.7% 49 / 54 CC 3 SCAR 3.5
CC
3
Cov
95%
render
2.0
_build_name
2.0
__ANON__
2.0
CRAP 1.4
↑ Summary
1 package Dancer::Template::Mustache;
2 3 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: Wrapper for the Mustache template system
4 3 $Dancer::Template::Mustache::VERSION = '1.0.1';
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Template::Mustache 1.0.2;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 require Dancer;
12  
13 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 require Dancer::Config;
18 3 Dancer::Config->import( 'setting' );
19  
20 3 extends 'Dancer::Template::Abstract';
21  
22 0 ▶sub _build_name { 'Dancer::Template::Mustache' }
Subroutine _build_name: not called CC=1 SCAR=6.9
23  
24 11 ▶sub default_tmpl_ext { "mustache" };
Subroutine default_tmpl_ext: called CC=1 SCAR=0.0
Pod documented
25  
26 has _template_path => (
27 is => 'ro',
28 lazy => 1,
29 default => sub {
30 3 ▶ setting( 'views' ) || $FindBin::Bin . '/views'
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
setting("views") or $FindBin::Bin . '/views' 1 2 3
31 },
32 3 );
33  
34 3 my %file_template; # cache for the templates
35  
36 sub render {
37 7 ▶ my ($self, $template, $tokens) = @_;
Subroutine render: called CC=2 SCAR=7.0
Pod documented
38  
39 7 my $_template_path = $self->_template_path;
40  
41 # remove the views part
42 7 $template =~ s#^\Q$_template_path\E/?##;
43  
44 7 ▶ my $mustache = $file_template{$template} ||= Template::Mustache->new(
Condition66%2/3
$file_template{$template} ||= "Template::Mustache"->new("template_path", path($self->_template_path, $template))
l!l&&r!l&&!r
250
MC/DC0%0/2
$file_template{$template} ||= "Template::Mustache"->new("template_path", path($self->_template_path, $template))
$file_template{$template} "Template::Mustache"->new("template_path", path($self->_template_path, $template))
Truth table66%2/3
A ||= B
A= $file_template{$template}B= "Template::Mustache"->new("template_path", path($self->_template_path, $template))
ABresult
1X1
011
000
45 template_path => path( $self->_template_path, $template )
46 );
47  
48 7 return $mustache->render($tokens);
49 }
50  
51 3 1;
52  
53 __END__
54  
55 =pod
56  
57 =encoding UTF-8
58  
59 =head1 NAME
60  
61 Dancer::Template::Mustache - Wrapper for the Mustache template system
62  
63 =head1 VERSION
64  
65 version 1.0.1
66  
67 =head1 SYNOPSIS
68  
69 # in config.yml
70 template: mustache
71  
72 # in the app
73 get '/style/:style' => sub {
74 template 'style' => {
75 style => param('style')
76 };
77 };
78  
79 # in views/style.mustache
80 That's a nice, manly {{style}} mustache you have there!
81  
82 =head1 DESCRIPTION
83  
84 This module is a L<Dancer> wrapper for L<Template::Mustache>.
85  
86 For now, the extension of the mustache templates must be C<.mustache>.
87  
88 Partials are supported, as are layouts. For layouts, the content of the inner
89 template is sent via the usual I<content> template variable. So a typical
90 mustached layout would look like:
91  
92 <body>
93 {{{ content }}}
94 </body>
95  
96 =head1 SEE ALSO
97  
98 The Mustache templating system: L<http://mustache.github.com/>
99  
100 L<Dancer::Template::Handlebars> - Dancer support for Handlebars, a templating system
101 that is a superset of Mustache.
102  
103 =head1 AUTHOR
104  
105 Yanick Champoux <yanick@babyl.dyndns.org>
106  
107 =head1 COPYRIGHT AND LICENSE
108  
109 This software is copyright (c) 2017, 2014, 2012 by Yanick Champoux.
110  
111 This is free software; you can redistribute it and/or modify it under
112 the same terms as the Perl 5 programming language system itself.
113  
114 =cut
↑ Summary