Compare commits

..
Author SHA1 Message Date
Graham Ollis b21db5cf22 v1.22 2012-08-21 20:39:02 -04:00
Graham Ollis 24990483e5 avoid deep recursion
when using a tt template for exceptions, and there is
an exception in the template, don't go into infinite
recursion.
2012-08-21 16:30:19 -04:00
Graham Ollis 4f5d3a0951 update Changes 2012-08-21 15:47:33 -04:00
Graham Ollis a72ec0e750 ignore cycles that are taken care of in Template::Provider#DESTROY 2012-08-21 15:44:33 -04:00
Graham Ollis 2956335d9e use Test::Memory::Cycle instead of find_cycle 2012-08-21 14:55:28 -04:00
Graham Ollis 7d1ac4eecd tt is private. 2012-08-21 14:49:58 -04:00
Graham Ollis 28ae3d62f8 return 1 on failure 2012-08-21 15:44:10 -03:00
5 changed files with 89 additions and 11 deletions
+5
View File
@@ -1,6 +1,11 @@
Revision history for Mojolicious::Plugin::TtRenderer Revision history for Mojolicious::Plugin::TtRenderer
{{$NEXT}} {{$NEXT}}
- Compatibility with Mojolicious 3.05+ (GH#24)
- Avoid deep recursion when exception template dies (GH#25,GH26)
- Fixed test failures (GH#27,GH#28)
1.21 June 5, 2012
- Fixed double TT rendering on error (Matthias Bethke (GH#21)) - Fixed double TT rendering on error (Matthias Bethke (GH#21))
- Cache templates in tmpdir by default (Marcus Ramberg) - Cache templates in tmpdir by default (Marcus Ramberg)
- Require Mojolicious 2.51 to avoid memory leaks (GH#19) - Require Mojolicious 2.51 to avoid memory leaks (GH#19)
+11 -3
View File
@@ -2,6 +2,7 @@ package Mojolicious::Plugin::TtRenderer::Engine;
use warnings; use warnings;
use strict; use strict;
use v5.10;
use base 'Mojo::Base'; use base 'Mojo::Base';
@@ -88,12 +89,19 @@ sub _render {
# Error # Error
unless ($ok) { unless ($ok) {
state $rendering_exception;
my $e = Mojo::Exception->new($self->tt->error.''); my $e = Mojo::Exception->new($self->tt->error.'');
$$output = ''; $$output = '';
$c->app->log->error(qq/Template error in "$t": $e/); $c->app->log->error(qq/Template error in "$t": $e/);
$c->render_exception($e);
$self->tt->error(''); unless($rendering_exception)
return 0; {
$rendering_exception = 1;
$c->render_exception($e);
$rendering_exception = 0;
$self->tt->error('');
}
} }
return 1; return 1;
+55
View File
@@ -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 + % %]
+4 -1
View File
@@ -15,4 +15,7 @@ eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@; if $@;
all_pod_coverage_ok(); plan tests => 2;
pod_coverage_ok('Mojolicious::Plugin::TtRenderer');
pod_coverage_ok('Mojolicious::Plugin::TtRenderer::Engine', { also_private => [qr{^tt$}] } );
+13 -6
View File
@@ -43,10 +43,17 @@ $t->get_ok('/')->status_is(200)
->content_like(qr/test123456/); ->content_like(qr/test123456/);
$t->get_ok('/blow')->status_is(500)->content_like(qr/file error - doesnotexist.tt: No such file or directory/); $t->get_ok('/blow')->status_is(500)->content_like(qr/file error - doesnotexist.tt: No such file or directory/);
eval " if(eval q{ use Devel::Cycle; 1 })
use Devel::Cycle 'find_cycle'; {
find_cycle(app, sub { Devel::Cycle::find_cycle(app, sub {
ok(0, 'Cycle found'); my $arg = shift;
# Template::Provider (from which M::P::T::Provider inherits) has some cycles which are freed manaully by
# its DESTROY method, so we skip reporting those cycles.
unless(scalar(scalar(grep { ref($_->[2]) eq 'Mojolicious::Plugin::TtRenderer::Provider' && $_->[1] =~ /^(HEAD|TAIL|LOOKUP)$/ } @$arg)) > 0)
{
#use YAML ();
#diag YAML::Dump([ map { [ $_->[0], $_->[1], ref($_->[2]), ref($_->[3]) ] } @$arg ]);
fail('Cycle found')
}
}); });
"; };