Skip to content

Commit

Permalink
Apply changes from PR #21
Browse files Browse the repository at this point in the history
* Recreated because I was a goof and included Makefile in the repo
  • Loading branch information
lestrrat committed Sep 29, 2015
1 parent 3eb6bc0 commit 2cf981c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ Changes
=======

{{$NEXT}}
* Apply changes from PR #21 as #22

0.00018 2015-01-04T06:28:41Z
* compatibility shim added to test cases so that the encoding tests will
Expand Down
7 changes: 7 additions & 0 deletions META.json
Expand Up @@ -52,6 +52,13 @@
"Scalar::Util" : "0",
"Text::Xslate" : "0.1045"
}
},
"test" : {
"requires" : {
"Devel::Cycle" : "0",
"PadWalker" : "0",
"Test::More" : "0"
}
}
},
"release_status" : "unstable",
Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -78,6 +78,18 @@ cause the previously created underlying Text::Xslate object to be cleared

## verbose

## line\_start

## tag\_start

## tag\_end

## warn\_handler

## die\_handler

## pre\_process\_handler

## suffix

Use this to enable TT2 compatible variable methods via Text::Xslate::Bridge::TT2 or Text::Xslate::Bridge::TT2Like
Expand Down
6 changes: 6 additions & 0 deletions cpanfile
Expand Up @@ -6,3 +6,9 @@ requires 'Text::Xslate', '0.1045';
on build => sub {
requires 'ExtUtils::MakeMaker', '6.36';
};

on test => sub {
requires 'Test::More';
requires 'Devel::Cycle';
requires 'PadWalker';
};
11 changes: 6 additions & 5 deletions lib/Catalyst/View/Xslate.pm
Expand Up @@ -238,8 +238,11 @@ sub process {
}

sub build_exposed_method {
my ( $self, $ctx, $code ) = @_;
return sub { $self->$code($ctx, @_) };
my ( $self, $ctx, $code ) = @_;
my $weak_ctx = $ctx;
weaken $weak_ctx;

return sub { $self->$code($weak_ctx, @_) };
}

sub render {
Expand All @@ -250,9 +253,7 @@ sub render {
if ($self->has_expose_methods) {
foreach my $exposed_method( keys %{$self->expose_methods} ) {
if(my $code = $self->can( $self->expose_methods->{$exposed_method} )) {
my $weak_ctx = $c;
weaken $weak_ctx;
$vars->{$exposed_method} = $self->build_exposed_method($weak_ctx, $code);
$vars->{$exposed_method} = $self->build_exposed_method($c, $code);
} else {
Catalyst::Exception->throw( "$exposed_method not found in Xslate view" );
}
Expand Down
28 changes: 28 additions & 0 deletions t/005_memory_leak.t
@@ -0,0 +1,28 @@
use strict;
use Test::More tests => 3;

use FindBin;
use lib "$FindBin::Bin/lib";

use Devel::Cycle;

use_ok('Catalyst::Test', 'TestApp');

my $ctx;
my $response;
ok((($response, $ctx) = ctx_request("/test_render?template=specified_template.tx&param=parameterized")), 'request ok');

#this is the kind that causes a mem leak
$ctx->view('Xslate::ExposeMethods')->render( $ctx, 'header.tx', $ctx->{stash} );

my $cycle_count = 0;
my $callback = sub { $cycle_count++ };

#shut up some warnings that mean nothing
%Devel::Cycle::already_warned = (
REGEXP => 1,
GLOB => 1,
);

find_cycle( $ctx, $callback );
is $cycle_count, 0, 'no reference cycles found';

0 comments on commit 2cf981c

Please sign in to comment.