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