From 77b9531fae4ad3b0d78f75e3c0e07a22333fbd73 Mon Sep 17 00:00:00 2001 From: Magnus Holm Date: Wed, 7 Sep 2011 11:04:25 +0200 Subject: [PATCH 1/2] Add test case for cycles --- t/tt_plugin_lite_app.t | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/t/tt_plugin_lite_app.t b/t/tt_plugin_lite_app.t index 29679ad..94ae154 100644 --- a/t/tt_plugin_lite_app.t +++ b/t/tt_plugin_lite_app.t @@ -36,4 +36,12 @@ my $t = Test::Mojo->new; # Simple TT template $t->get_ok('/')->status_is(200) - ->content_like(qr/test123456/); \ No newline at end of file + ->content_like(qr/test123456/); + +eval " + use Devel::Cycle 'find_cycle'; + find_cycle(app, sub { + ok(0, 'Cycle found'); + }); +"; + From bd48aa5066b32683cdac9daf11569dc273c5f65f Mon Sep 17 00:00:00 2001 From: Magnus Holm Date: Wed, 7 Sep 2011 11:05:55 +0200 Subject: [PATCH 2/2] Fix cycles --- lib/Mojolicious/Plugin/TtRenderer/Engine.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index 1855f5a..173e229 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -10,11 +10,13 @@ use File::Spec (); use Mojo::ByteStream 'b'; use Template (); use Cwd qw/abs_path/; +use Scalar::Util 'weaken'; __PACKAGE__->attr('tt'); sub build { my $self = shift->SUPER::new(@_); + weaken($self->{app}); $self->_init(@_); return sub { $self->_render(@_) } } @@ -130,6 +132,7 @@ use strict; use warnings; use base 'Template::Provider'; +use Scalar::Util 'weaken'; sub new { my $class = shift; @@ -139,6 +142,7 @@ sub new { my $self = $class->SUPER::new(%params); $self->renderer($renderer); + weaken($self->{renderer}); return $self; }