[Catalyst-commits] r10681 - in Catalyst-Runtime/5.80/trunk/t: . lib
lib/TestApp/Controller
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Fri Jun 26 19:45:31 GMT 2009
Author: rafl
Date: 2009-06-26 19:45:30 +0000 (Fri, 26 Jun 2009)
New Revision: 10681
Added:
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/ContextClosure.pm
Catalyst-Runtime/5.80/trunk/t/live_component_controller_context_closure.t
Modified:
Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm
Log:
Add test for ContextClosure.
Added: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/ContextClosure.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/ContextClosure.pm (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/ContextClosure.pm 2009-06-26 19:45:30 UTC (rev 10681)
@@ -0,0 +1,28 @@
+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;
Modified: Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm 2009-06-26 17:34:25 UTC (rev 10680)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp.pm 2009-06-26 19:45:30 UTC (rev 10681)
@@ -13,10 +13,32 @@
/;
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 {
Added: Catalyst-Runtime/5.80/trunk/t/live_component_controller_context_closure.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/live_component_controller_context_closure.t (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/live_component_controller_context_closure.t 2009-06-26 19:45:30 UTC (rev 10681)
@@ -0,0 +1,28 @@
+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);
+}
More information about the Catalyst-commits
mailing list