Cake/Plugins/View.pm

filter: Statementstmt 72.0% 31 / 43 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 61.7% 42 / 68 CC 6 SCAR 11.4
CC
6
Cov
65%
template
5.2
_render_template
3.7
layout
2.0
CRAP 3.1
« Cake/Plugins/I18N.pm ↑ Summary Cake/Utils/Accessor.pm »
1 package Cake::Plugins::View;
2 1 ▶use Cake 'Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Cake::View::TT;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 1 my $template;
7 my $settings;
8
9 1 ▶sub template {
Subroutine template: called CC=4 SCAR=16.4
Pod undocumented
10 1 ▶ return $template if $template;
Branch: 1 branch
BranchTrueFalseTotal
if $template 0 1 1
11 1 ▶ $settings ||= $_[1] || settings;
Condition33%2/6
$settings ||= $_[1] || settings()
l!l&&r!l&&!r
010
$_[1] || settings()
l!l&&r!l&&!r
010
MC/DC0%0/3
$settings ||= $_[1] || settings()
$settings $_[1] settings()
Truth table0%0/4
A ||= B || C
A= $settingsB= $_[1]C= settings()
ABCresult
1XX1
01X1
0011
0000
12
13 $template = new Cake::View::TT({
14 path => $settings->{path},
15 layout => $settings->{layout},
16 DEBUG => $settings->{Debug}
17 1 });
18
19 1 return $template;
20 }
21
22 1 ▶sub render {
Subroutine render: called CC=1 SCAR=0.0
Pod undocumented
23 1 my $self = $_[0];
24 1 my $temp = &_render_template(@_);
25 1 $self->body(Encode::encode('UTF-8',$temp));
26 }
27
28 1 ▶sub _render_template {
Subroutine _render_template: called CC=3 SCAR=13.0
29
30 1 my $self = shift;
31 1 my $file = shift;
32 1 my $vars = shift;
33 1 ▶ $vars = {} if !$vars;
Branch: 1 branch
BranchTrueFalseTotal
unless $vars 1 0 1
34
35 ###stash pass as default with Cake object as c
36 1 $vars = {%{$self->stash},%{$vars},c=>$self};
37 1 my $temp;
38 1 eval {
39 1 $temp = template->render(
40 $file,
41 $vars
42 );
43 };
44
45 1 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
46 0 my $error = $@;
47 ##get message & line number
48 0 my ($msg,$l) = ($error->{message} =~ /(.*?) at .*? line (\d+)/);
49
50 0 open my $fh, '<', $error->{file};
51 0 read $fh, my $buf, $error->{pos}+1;
52 0 close $fh;
53
54 #count number of lines
55 0 my @lines = split /\n/,$buf;
56 0 my $line = scalar @lines + ($l-1);
57 die {
58 caller => [
59 __PACKAGE__,
60 $error->{file},
61 $line
62 ],
63 file => $error->{file},
64 pos => $error->{pos},
65 0 message => $msg
66 }
67 }
68 1 return $temp;
69 }
70
71 0 ▶sub layout {
Subroutine layout: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my $self = shift;
73 0 my $layout = shift;
74 0 template->{layout} = $layout;
75 0 return $self;
76 }
77
78 1 register();
79
80 1 1;
81
82 __END__
« Cake/Plugins/I18N.pm ↑ Summary Cake/Utils/Accessor.pm »