Fix the way Catalyst::Plugin::Server adds custom dispatch types
[catagits/Catalyst-Runtime.git] / t / lib / TestApp.pm
1 package TestApp;
2
3 use strict;
4 use Catalyst qw/
5     Test::Errors 
6     Test::Headers 
7     Test::Plugin
8     Test::Inline
9     +TestApp::Plugin::FullyQualified
10     +TestApp::Plugin::AddDispatchTypes
11 /;
12 use Catalyst::Utils;
13
14 our $VERSION = '0.01';
15
16 TestApp->config( name => 'TestApp', root => '/some/dir' );
17
18 TestApp->setup;
19
20 sub index : Private {
21     my ( $self, $c ) = @_;
22     $c->res->body('root index');
23 }
24
25 sub global_action : Private {
26     my ( $self, $c ) = @_;
27     $c->forward('TestApp::View::Dump::Request');
28 }
29
30 sub execute {
31     my $c      = shift;
32     my $class  = ref( $c->component( $_[0] ) ) || $_[0];
33     my $action = $_[1]->reverse;
34
35     my $method;
36
37     if ( $action =~ /->(\w+)$/ ) {
38         $method = $1;
39     }
40     elsif ( $action =~ /\/(\w+)$/ ) {
41         $method = $1;
42     }
43     elsif ( $action =~ /^(\w+)$/ ) {
44         $method = $action;
45     }
46
47     if ( $class && $method && $method !~ /^_/ ) {
48         my $executed = sprintf( "%s->%s", $class, $method );
49         my @executed = $c->response->headers->header('X-Catalyst-Executed');
50         push @executed, $executed;
51         $c->response->headers->header(
52             'X-Catalyst-Executed' => join ', ',
53             @executed
54         );
55     }
56
57     return $c->SUPER::execute(@_);
58 }
59
60 # Replace the very large HTML error page with
61 # useful info if something crashes during a test
62 sub finalize_error {
63     my $c = shift;
64     
65     $c->next::method(@_);
66     
67     $c->res->status(500);
68     $c->res->body( 'FATAL ERROR: ' . join( ', ', @{ $c->error } ) );
69 }
70
71 sub class_forward_test_method :Private {
72     my ( $self, $c ) = @_;
73     $c->response->headers->header( 'X-Class-Forward-Test-Method' => 1 );
74 }
75
76 sub class_go_test_method :Private {
77     my ( $self, $c ) = @_;
78     $c->response->headers->header( 'X-Class-Go-Test-Method' => 1 );
79 }
80
81 sub class_visit_test_method :Private {
82     my ( $self, $c ) = @_;
83     $c->response->headers->header( 'X-Class-Visit-Test-Method' => 1 );
84 }
85
86 sub loop_test : Local {
87     my ( $self, $c ) = @_;
88
89     for( 1..1001 ) {
90         $c->forward( 'class_forward_test_method' );
91     }
92 }
93
94 sub recursion_test : Local {
95     my ( $self, $c ) = @_;
96     $c->forward( 'recursion_test' );
97 }
98
99 {
100     no warnings 'redefine';
101     sub Catalyst::Log::error { }
102 }
103
104 # Make sure we can load Inline plugins. 
105
106 package Catalyst::Plugin::Test::Inline;
107
108 use strict;
109
110 use base qw/Catalyst::Base Class::Data::Inheritable/;
111
112 1;