blib/lib/Mojolicious/Plugin/ToolkitRenderer.pm

filter: Statementstmt 82.9% 34 / 41 Branchbran 25.0% 3 / 12 Conditioncond 25.0% 5 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 54.7% 52 / 95 CC 15 SCAR 34.1
CC
15
Cov
58%
__ANON__
60.6
register
9.7
BEGIN
1.0
CRAP 30.1
↑ Summary
1 package Mojolicious::Plugin::ToolkitRenderer;
2 # ABSTRACT: Template Toolkit Renderer Mojolicious Plugin
3  
4 2 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Mojo::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
13 2 require Template;
14 2 Template->import;
15 }
16  
17 2 our $VERSION = '1.15'; # VERSION
18  
19 1 ▶sub register {
Subroutine register: called CC=5 SCAR=22.8
Pod documented
20 1 my ( $self, $app, $settings ) = @_;
21  
22 1 ▶ $settings->{config}{RELATIVE} //= 1;
Condition50%1/2
$settings->{"config"}{"RELATIVE"} //= 1
l!l
10
MC/DC0%0/1
$settings->{"config"}{"RELATIVE"} //= 1
$settings->{"config"}{"RELATIVE"}
Truth table50%1/2
A
A= $settings->{"config"}{"RELATIVE"}
Aresult
11
00
23 1 ▶ $settings->{config}{EVAL_PERL} //= 0;
Condition50%1/2
$settings->{"config"}{"EVAL_PERL"} //= 0
l!l
10
MC/DC0%0/1
$settings->{"config"}{"EVAL_PERL"} //= 0
$settings->{"config"}{"EVAL_PERL"}
Truth table50%1/2
A
A= $settings->{"config"}{"EVAL_PERL"}
Aresult
11
00
24 1 ▶ $settings->{config}{INCLUDE_PATH} //= $app->renderer->paths;
Condition33%1/3
$settings->{"config"}{"INCLUDE_PATH"} //= $app->renderer->paths
l!l&&r!l&&!r
010
MC/DC0%0/2
$settings->{"config"}{"INCLUDE_PATH"} //= $app->renderer->paths
$settings->{"config"}{"INCLUDE_PATH"} $app->renderer->paths
Truth table33%1/3
A //= B
A= $settings->{"config"}{"INCLUDE_PATH"}B= $app->renderer->paths
ABresult
1X1
011
000
25  
26 1 my $template = Template->new( $settings->{config} );
27  
28 1 ▶ $settings->{context}->( $template->context ) if ( $settings->{context} );
Branch: 1 branch
BranchTrueFalseTotal
if $settings->{"context"} 1 0 1
29  
30 1 ▶ $app->renderer->add_handler( tt => sub {
Subroutine __ANON__: called CC=11 SCAR=41.0
31 1 my ( $renderer, $controller, $output, $options ) = @_;
32 1 ▶ my $inline = $settings->{settings}{inline_template} || 'inline';
Condition50%1/2
$settings->{'settings'}{'inline_template'} || 'inline'
l!l
10
MC/DC0%0/1
$settings->{'settings'}{'inline_template'} || 'inline'
$settings->{'settings'}{'inline_template'}
Truth table50%1/2
A
A= $settings->{'settings'}{'inline_template'}
Aresult
11
00
33  
34 $template->process(
35 ( ( $options->{$inline} ) ? \$options->{$inline} : $renderer->template_name($options) ),
36 {
37 content => $controller->content,
38 1 ▶ %{ $controller->stash },
Condition50%1/2
$settings->{'settings'}{'controller'} || 'c'
l!l
10
MC/DC0%0/1
$settings->{'settings'}{'controller'} || 'c'
$settings->{'settings'}{'controller'}
Truth table50%1/2
A
A= $settings->{'settings'}{'controller'}
Aresult
11
00
39 ( $settings->{settings}{controller} || 'c' ) => $controller,
40 },
41 $output,
42 1 ▶ ) || do {
Branch: 2 branches
BranchTrueFalseTotal
$template->process($options->{$inline} ? \$options->{$inline} : $renderer->template_name($options), {"content", $controller->content, %{$controller->stash;}, $settings->{"settings"}{"controller"} || "c", $controller}, $output) or do { if (ref $settings->{"settings"}{"error_handler"} eq "CODE") { $settings->{"settings"}{"error_handler"}->($controller, $renderer, $app, $template); } else { unless ($template->error and $template->error eq "file error - exception.html.tt: not found" || $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found') { $$output = $template->error; $controller->res->headers->content_type("text/plain"); $controller->log->error($template->error); $controller->rendered($template->error && $template->error =~ /not found/u ? 404 : 500); } ; } } 1 0 1
$options->{$inline} ? : 1 0 1
43 0 ▶ if ( ref( $settings->{settings}{error_handler} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $settings->{'settings'}{'error_handler'} eq 'CODE') { } 0 0 0
44 0 $settings->{settings}{error_handler}->( $controller, $renderer, $app, $template );
45 }
46 else {
47 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($template->error and $template->error eq "file error - exception.html.tt: not found" || $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found') 0 0 0
Condition0%0/6
$template->error and $template->error eq "file error - exception.html.tt: not found" || $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found'
!ll&&!rl&&r
000
$template->error eq "file error - exception.html.tt: not found" or $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found'
l!l&&r!l&&!r
000
MC/DC0%0/3
$template->error and $template->error eq "file error - exception.html.tt: not found" || $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found'
$template->error $template->error eq "file error - exception.html.tt: not found" $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found'
Truth table0%0/4
A and B or C
A= $template->errorB= $template->error eq "file error - exception.html.tt: not found"C= $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found'
ABCresult
0XX0
1000
11X1
1011
48 $template->error and (
49 $template->error eq 'file error - exception.html.tt: not found' or
50 $template->error eq 'file error - exception.' . $app->mode . '.html.tt: not found'
51 )
52 ) {
53 0 $$output = $template->error;
54 0 $controller->res->headers->content_type('text/plain');
55  
56 0 $controller->log->error( $template->error );
57 0 ▶ $controller->rendered(
Branch: 1 branch
BranchTrueFalseTotal
$template->error && $template->error =~ /not found/u ? : 0 0 0
Condition0%0/3
$template->error and $template->error =~ /not found/u
!ll&&!rl&&r
000
MC/DC0%0/2
$template->error and $template->error =~ /not found/u
$template->error $template->error =~ /not found/u
Truth table0%0/3
A and B
A= $template->errorB= $template->error =~ /not found/u
ABresult
0X0
100
111
58 ( $template->error and $template->error =~ /not found/ ) ? 404 : 500
59 );
60 }
61 }
62 };
63  
64 1 return $$output;
65 1 } );
66  
67 $app->helper(
68 1 ▶ render_tt => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
69 1 shift->render( handler => 'tt', @_ );
70 }
71 1 );
72  
73 1 return;
74 }
75  
76 2 1;
77  
78 __END__
↑ Summary