Compare commits

...

9 Commits

Author SHA1 Message Date
Graham Ollis
7455ae1be8 v1.23 2012-08-23 15:27:07 -04:00
Graham Ollis
870d195761 use die instead of render_exception 2012-08-23 15:26:38 -04:00
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
6 changed files with 83 additions and 18 deletions

View File

@@ -1,6 +1,14 @@
Revision history for Mojolicious::Plugin::TtRenderer
{{$NEXT}}
- Use die instead of render_exception (GH#29)
1.22 August 21, 2012
- 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))
- Cache templates in tmpdir by default (Marcus Ramberg)
- Require Mojolicious 2.51 to avoid memory leaks (GH#19)

View File

@@ -39,7 +39,6 @@ version_regexp = ^release/(.*)
[HasVersionTests]
[MetaTests]
[ReadmeFromPod]
[PodCoverageTests]
[Manifest]
[NextRelease]

View File

@@ -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');
}
@@ -86,15 +87,7 @@ sub _render {
my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params);
# Error
unless ($ok) {
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('');
return 0;
}
die $self->tt->error unless $ok;
return 1;
}

55
t/deep_recursion.t Normal file
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 + % %]

View File

@@ -15,4 +15,7 @@ eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
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$}] } );

View File

@@ -43,10 +43,17 @@ $t->get_ok('/')->status_is(200)
->content_like(qr/test123456/);
$t->get_ok('/blow')->status_is(500)->content_like(qr/file error - doesnotexist.tt: No such file or directory/);
eval "
use Devel::Cycle 'find_cycle';
find_cycle(app, sub {
ok(0, 'Cycle found');
if(eval q{ use Devel::Cycle; 1 })
{
Devel::Cycle::find_cycle(app, sub {
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')
}
});
";
};