diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index e75eb79..453840f 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -2,6 +2,7 @@ package Mojolicious::Plugin::TtRenderer::Engine; use warnings; use strict; +use v5.10; use base 'Mojo::Base'; @@ -30,7 +31,7 @@ sub _init { my $dir; my $app = delete $args{mojo} || delete $args{app}; if($dir=$args{cache_dir}) { - + if($app && substr($dir,0,1) ne '/') { $dir=$app->home->rel_dir('tmp/ctpl'); } @@ -88,11 +89,19 @@ sub _render { # Error unless ($ok) { + state $rendering_exception; + my $e = Mojo::Exception->new($self->tt->error.''); $$output = ''; $c->app->log->error(qq/Template error in "$t": $e/); - $c->render_exception($e); - $self->tt->error(''); + + unless($rendering_exception) + { + $rendering_exception = 1; + $c->render_exception($e); + $rendering_exception = 0; + $self->tt->error(''); + } } return 1; diff --git a/t/deep_recursion.t b/t/deep_recursion.t new file mode 100644 index 0000000..27f30bf --- /dev/null +++ b/t/deep_recursion.t @@ -0,0 +1,55 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +#BEGIN { $ENV{MOJO_MODE}='testing'; }; + +use utf8; + +use Test::More tests => 3; + +use Mojolicious::Lite; +use Test::Mojo; + +# Silence +app->log->level('fatal'); + +plugin 'tt_renderer'; + +get '/exception' => sub { die }; + +#say app->mode; +#app->start; +#exit; + +my $t = Test::Mojo->new; + +$t->app->renderer->default_handler('tt'); + +my $deep_recursion = 0; + +do { + local $SIG{__WARN__} = sub { + my $warning = shift; + if($warning =~ /Deep recursion/) { + $deep_recursion = 1; + die $warning; + } + }; + $t->get_ok('/exception') + ->status_is(500); +}; + +ok !$deep_recursion, 'no deep recursion'; + +__DATA__ + +@@ exception.development.html.tt +[% 1 + % %] + +@@ exception.html.tt +[% 1 + % %] + +@@ exception.testing.html.tt +[% 1 + % %]