| 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.1.0'; | |||||||||||||||||||
| 5 | 3 | ▶ | use 5.10.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | use Template::Mustache 1.0.2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use FindBin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | require Dancer; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 3 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | ▶ | use Dancer::Config qw/ setting /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | extends 'Dancer::Template::Abstract'; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub _build_name { 'Dancer::Template::Mustache' } | ||||||||||||||||||
|
Subroutine
_build_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 11 | ▶ | sub default_tmpl_ext { "mustache" }; | ||||||||||||||||||
|
Subroutine
default_tmpl_ext: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | has _template_path => ( | ||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||
| 29 | lazy => 1, | ||||||||||||||||||||
| 30 | 3 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 31 | 3 | ▶ | setting( 'views' ) || $FindBin::Bin . '/views' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||
| 33 | 3 | ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | has caching => ( | ||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||
| 37 | lazy => 1, | ||||||||||||||||||||
| 38 | 3 | ▶ | default => sub { $_[0]->config->{cache_templates} // 1 }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]->config->{"cache_templates"} // 1
MC/DC0%0/1
$_[0]->config->{"cache_templates"} // 1
$_[0]->config->{"cache_templates"}
Truth table50%1/2
A
A= $_[0]->config->{"cache_templates"}
| |||||||||||||||||||||
| 39 | 3 | ); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 3 | my %file_template; # cache for the templates | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 7 | ▶ | sub render { | ||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 44 | 7 | my ($self, $template, $tokens) = @_; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 7 | my $_template_path = $self->_template_path; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | # remove the views part | ||||||||||||||||||||
| 49 | 7 | $template =~ s#^\Q$_template_path\E/?##; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 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))
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))
| |||||||||||||||||||||
| 52 | template_path => path( $self->_template_path, $template ) | ||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 7 | ▶ | delete $file_template{$template} unless $self->caching; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 7 | return $mustache->render($tokens); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 3 | 1; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||