1use strict; 2use warnings; 3use Test::More; 4use B::Deparse; 5 6use FindBin; 7use lib "$FindBin::Bin/lib"; 8 9use Catalyst::Test 'TestApp'; 10 11{ 12 my ($resp, $ctx) = ctx_request('/affe/no_closure'); 13 is($resp->content, 'no_closure'); 14 is($ctx->count_leaks, 0, 'no leaks reported without stashed closures'); 15} 16 17{ 18 my ($resp, $ctx) = ctx_request('/affe/leak_closure'); 19 is($resp->content, 'leak_closure'); 20 is($ctx->count_leaks, 1, 'one leak reported with a stashed closure, closing over $ctx'); 21 22 my $leak = $ctx->first_leak; 23# is($leak->{var}, '$ctx', 'right variable name reported for closed over context'); 24# like( 25# B::Deparse->new->coderef2text($leak->{code}), 26# qr/leaky closure/, 27# 'right code reference reported for leaky closure', 28# ); 29} 30 31{ 32 my ($resp, $ctx) = ctx_request('/affe/weak_closure'); 33 is($resp->content, 'weak_closure'); 34 is($ctx->count_leaks, 0, 'no leak reported with a stashed closure, closing over a weak $ctx'); 35} 36 37{ 38 my ($resp, $ctx) = ctx_request('/affe/leak_closure_indirect'); 39 is($resp->content, 'leak_closure_indirect'); 40 is($ctx->count_leaks, 1, 'one leak reported with stashed closure, closing over something with a reference to $ctx'); 41} 42 43{ 44 my ($resp, $ctx) = ctx_request('/affe/weak_closure_indirect'); 45 is($resp->content, 'weak_closure_indirect'); 46 is($ctx->count_leaks, 0, 'no leak when closing over something holding a weak reference to $ctx'); 47} 48 49{ 50 my ($resp, $ctx) = ctx_request('/affe/stashed_ctx'); 51 is($resp->content, 'stashed_ctx'); 52 is($ctx->count_leaks, 1, 'one leak found when stashing $ctx'); 53} 54 55{ 56 my ($resp, $ctx) = ctx_request('/affe/stashed_weak_ctx'); 57 is($resp->content, 'stashed_weak_ctx'); 58 is($ctx->count_leaks, 0, 'no leak when stashing a weak $ctx'); 59} 60 61done_testing; 62