Add test for looping DispatchType::Chained->list
Ash Berlin [Mon, 16 Mar 2009 13:56:14 +0000 (13:56 +0000)]
lib/Catalyst/Dispatcher.pm
t/lib/TestApp/Controller/Root.pm
t/live_recursion.t
t/unit_core_action_chained.t [new file with mode: 0644]

index 2b81250..e8e201e 100644 (file)
@@ -571,6 +571,11 @@ sub setup_actions {
     $self->_load_dispatch_types( @{ $self->postload_dispatch_types } );
 
     return unless $c->debug;
+    $self->_display_action_tables($c);
+}
+
+sub _display_action_tables {
+    my ($self, $c) = @_;
 
     my $column_width = Catalyst::Utils::term_width() - 20 - 36 - 12;
     my $privates = Text::SimpleTable->new(
@@ -624,6 +629,20 @@ sub _load_dispatch_types {
     return @loaded;
 }
 
+# Dont document this until someone else is happy with beaviour. Ash 2009/03/16
+sub dispatch_type {
+    my ($self, $name) = @_;
+
+    unless ($name =~ s/^\+//) {
+        $name = "Catalyst::DispatchType::" . $name;
+    }
+
+    for (@{ $self->dispatch_types }) {
+        return $_ if ref($_) eq $name;
+    }
+    return undef;
+}
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm
index 53d79e2..a3978d6 100644 (file)
@@ -20,4 +20,8 @@ sub localregex : LocalRegex('^localregex$') {
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub chain_to_self : Chained('chain_to_self') PathPart('') CaptureArgs(1) { }
+
+sub chain_recurse_endoint : Chained('chain_to_self') Args(0) { }
+
 1;
index 6e55877..db0472e 100644 (file)
@@ -23,3 +23,4 @@ SKIP:
     ok( !$response->is_success, 'Response Not Successful' );
     is( $response->header('X-Catalyst-Error'), 'Deep recursion detected calling "/recursion_test"', 'Deep Recursion Detected' );
 }
+
diff --git a/t/unit_core_action_chained.t b/t/unit_core_action_chained.t
new file mode 100644 (file)
index 0000000..1d4f4a8
--- /dev/null
@@ -0,0 +1,26 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use Test::More tests => 3;
+
+
+use TestApp;
+
+my $dispatch_type = TestApp->dispatcher->dispatch_type('Chained');
+isa_ok($dispatch_type, "Catalyst::DispatchType::Chained", "got dispatch type");
+
+# This test was failing due to recursion/OOM. set up an alarm so things dont
+# runaway
+local $SIG{ALRM} = sub { 
+    ok(0, "Chained->list didn't loop");
+    die "alarm expired - test probably looping";
+};
+alarm 10;
+
+$dispatch_type->list("TestApp");
+ok(1, "Chained->list didn't loop");