Handlebars.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 83.3% 5 / 6 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 1 totaltotal 93.9% 62 / 66 CC 6 SCAR 6.7
CC
6
Cov
96%
_build_helpers
4.1
__ANON__
2.0
__ANON__
2.0
CRAP 2.0
↑ Summary Handlebars/Helpers.pm »
1 package Dancer2::Template::Handlebars 1.00;
2  
3 # ABSTRACT: Dancer2 wrapper for Handlebars templating engine
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Text::Handlebars;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Module::Runtime qw/ use_module /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 with 'Dancer2::Core::Role::Template';
14  
15 3 ▶has '+default_tmpl_ext' => ( default => sub {'hbs'}, );
Subroutine __ANON__: called CC=1 SCAR=0.0
16  
17 4 has helpers => (
18 is => 'ro',
19 lazy => 1,
20 builder => '_build_helpers',
21 );
22  
23 has _engine => (
24 is => 'ro',
25 lazy => 1,
26 3 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 3 my $self = shift;
28 3 return Text::Handlebars->new( helpers => $self->helpers, );
29 },
30 4 );
31  
32 has _config => (
33 is => 'ro',
34 lazy => 1,
35 3 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
36 3 ▶ return $_[0]->settings->{engines}->{handlebars} || {};
Condition100%2/2
$_[0]->settings->{'engines'}{'handlebars'} || {}
l!l
21
MC/DC100%1/1
$_[0]->settings->{'engines'}{'handlebars'} || {}
$_[0]->settings->{'engines'}{'handlebars'}
Truth table100%2/2
A
A= $_[0]->settings->{'engines'}{'handlebars'}
Aresult
11
00
37 },
38 4 );
39  
40 3 ▶sub _build_helpers {
Subroutine _build_helpers: called CC=4 SCAR=14.0
41 3 my $self = shift;
42  
43 3 my %helpers;
44  
45 3 ▶ if ( my $h = $self->_config->{helpers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = $self->_config->{"helpers"}) 1 2 3
46 1 ▶ for my $module ( ref $h ? @$h : $h ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $h ? : 1 0 1
47 1 ▶ my %h = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 1 use_module($module)->HANDLEBARS_HELPERS
49 }
50 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 die "couldn't import helper functions from $module: $_";
52 1 };
53  
54 1 @helpers{ keys %h } = values %h;
55 }
56 }
57  
58 3 return \%helpers;
59 }
60  
61 7 ▶sub render {
Subroutine render: called CC=2 SCAR=6.9
Pod undocumented
62 7 my ( $self, $template, $tokens ) = @_;
63  
64 7 my $method = 'render';
65  
66 7 ▶ if ( ref $template ) { # it's a ref to a string
Branch: 1 branch
BranchTrueFalseTotal
if (ref $template) 1 6 7
67 1 $template = $$template;
68 1 $method .= '_string';
69 }
70  
71 7 return $self->_engine->$method( $template, $tokens );
72 }
73  
74 4 1;
75  
76 __END__
↑ Summary Handlebars/Helpers.pm »