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