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