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