blib/lib/OX/View/TT.pm

filter: Statementstmt 100% 40 / 40 Branchbran 50.0% 2 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 96.7% 59 / 61 CC 4 SCAR 3.4
CC
4
Cov
96%
render
2.0
template
2.0
_get_all_template_params
2.0
CRAP 1.4
↑ Summary
1 package OX::View::TT;
2 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 $OX::View::TT::AUTHORITY = 'cpan:DOY';
4 }
5 5 $OX::View::TT::VERSION = '0.02';
6 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 # ABSTRACT: View wrapper class for TT renderers
8  
9 5 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 5 has 'template_root' => (
14 is => 'ro',
15 isa => 'Path::Class::Dir',
16 coerce => 1,
17 required => 1,
18 );
19  
20 has 'template_config' => (
21 is => 'ro',
22 isa => 'HashRef',
23 lazy => 1,
24 12 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 5 );
26  
27 has 'tt' => (
28 is => 'ro',
29 isa => 'Template',
30 lazy => 1,
31 12 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 12 my $self = shift;
33 Template->new(
34 INCLUDE_PATH => $self->template_root,
35 12 %{ $self->template_config }
36 )
37 }
38 5 );
39  
40 has template_params => (
41 is => 'ro',
42 isa => 'HashRef',
43 10 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 5 );
45  
46 10 ▶sub _get_all_template_params {
Subroutine _get_all_template_params: called CC=2 SCAR=6.9
47 10 my ($self, $r, $params) = @_;
48 return +{
49 10 %{ $self->template_params },
50 base => $r->script_name,
51 3 ▶ uri_for => sub { $r->uri_for(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 m => $r->mapping,
53 10 ▶ %{ $params || {} }
Condition100%2/2
$params || {}
l!l
82
MC/DC100%1/1
$params || {}
$params
Truth table100%2/2
A
A= $params
Aresult
11
00
54 }
55 }
56  
57  
58 10 ▶sub render {
Subroutine render: called CC=2 SCAR=7.0
Pod documented
59 10 my ($self, $r, $template, $params) = @_;
60 10 my $out = '';
61 10 ▶ $self->tt->process(
Branch: 1 branch
BranchTrueFalseTotal
$self->tt->process($template, $self->_get_all_template_params($r, $params), \$out) or confess($self->tt->error) 10 0 10
62 $template,
63 $self->_get_all_template_params( $r, $params ),
64 \$out
65 ) || confess $self->tt->error;
66 10 $out;
67 }
68  
69  
70 5 ▶sub template {
Subroutine template: called CC=2 SCAR=7.0
Pod documented
71 5 my $self = shift;
72 5 my ($r) = @_;
73  
74 5 my %params = %{ $r->mapping };
75 confess("Must supply a 'template' parameter")
76 5 ▶ unless exists $params{template};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"template"} 0 5 5
77  
78 5 return $self->render($r, $params{template}, \%params);
79 }
80  
81 5 __PACKAGE__->meta->make_immutable;
82 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84  
85 5 1;
86  
87 __END__
↑ Summary