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; } 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'); + }); +"; +