/;
use Catalyst::Utils;
+use Moose;
+use namespace::autoclean;
+
our $VERSION = '0.01';
TestApp->config( name => 'TestApp', root => '/some/dir' );
+if (eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
+ with 'CatalystX::LeakChecker';
+
+ has leaks => (
+ is => 'ro',
+ default => sub { [] },
+ );
+}
+
+sub found_leaks {
+ my ($ctx, @leaks) = @_;
+ push @{ $ctx->leaks }, @leaks;
+}
+
+sub count_leaks {
+ my ($ctx) = @_;
+ return scalar @{ $ctx->leaks };
+}
+
TestApp->setup;
sub index : Private {
--- /dev/null
+package TestApp::Controller::ContextClosure;
+
+use Moose;
+
+BEGIN {
+ extends 'Catalyst::Controller';
+ with 'Catalyst::Component::ContextClosure';
+}
+
+sub normal_closure : Local {
+ my ($self, $ctx) = @_;
+ $ctx->stash(closure => sub {
+ $ctx->response->body('from normal closure');
+ });
+ $ctx->response->body('stashed normal closure');
+}
+
+sub context_closure : Local {
+ my ($self, $ctx) = @_;
+ $ctx->stash(closure => $self->make_context_closure(sub {
+ $ctx->response->body('from context closure');
+ }, $ctx));
+ $ctx->response->body('stashed context closure');
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
--- /dev/null
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ unless (eval 'use CatalystX::LeakChecker; 1') {
+ plan skip_all => 'CatalystX::LeakChecker required for this test';
+ }
+
+ plan tests => 4;
+}
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Catalyst::Test 'TestApp';
+
+{
+ my ($resp, $ctx) = ctx_request('/contextclosure/normal_closure');
+ ok($resp->is_success);
+ is($ctx->count_leaks, 1);
+}
+
+{
+ my ($resp, $ctx) = ctx_request('/contextclosure/context_closure');
+ ok($resp->is_success);
+ is($ctx->count_leaks, 0);
+}