r12983@zaphod: kd | 2008-04-28 18:10:27 +1000
[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
17TestApp->setup;
18
e0e47c71 19sub index : Private {
20 my ( $self, $c ) = @_;
369c09bc 21 $c->res->body('root index');
e0e47c71 22}
23
e5d7f18c 24sub global_action : Private {
2656a6de 25 my ( $self, $c ) = @_;
26 $c->forward('TestApp::View::Dump::Request');
27}
28
dd4e6fd2 29sub execute {
4d989a5d 30 my $c = shift;
31 my $class = ref( $c->component( $_[0] ) ) || $_[0];
f3414019 32 my $action = $_[1]->reverse;
dd4e6fd2 33
34 my $method;
35
4d989a5d 36 if ( $action =~ /->(\w+)$/ ) {
37 $method = $1;
dd4e6fd2 38 }
4d989a5d 39 elsif ( $action =~ /\/(\w+)$/ ) {
40 $method = $1;
dd4e6fd2 41 }
01ba879f 42 elsif ( $action =~ /^(\w+)$/ ) {
43 $method = $action;
44 }
45
ba599d1c 46 if ( $class && $method && $method !~ /^_/ ) {
1408d0a4 47 my $executed = sprintf( "%s->%s", $class, $method );
fbcc39ad 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 );
1408d0a4 54 }
fbcc39ad 55
dd4e6fd2 56 return $c->SUPER::execute(@_);
57}
58
8153c836 59# Replace the very large HTML error page with
60# useful info if something crashes during a test
61sub 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
1627551a 70sub class_forward_test_method :Private {
86d993ab 71 my ( $self, $c ) = @_;
72 $c->response->headers->header( 'X-Class-Forward-Test-Method' => 1 );
73}
74
2f381252 75sub class_go_test_method :Private {
76 my ( $self, $c ) = @_;
77 $c->response->headers->header( 'X-Class-Go-Test-Method' => 1 );
78}
79
1627551a 80sub loop_test : Local {
81 my ( $self, $c ) = @_;
82
83 for( 1..1001 ) {
84 $c->forward( 'class_forward_test_method' );
85 }
86}
87
88sub recursion_test : Local {
89 my ( $self, $c ) = @_;
90 $c->forward( 'recursion_test' );
91}
92
369c09bc 93{
94 no warnings 'redefine';
95 sub Catalyst::Log::error { }
96}
4ca147fa 97
98# Make sure we can load Inline plugins.
99
100package Catalyst::Plugin::Test::Inline;
101
102use strict;
103
104use base qw/Catalyst::Base Class::Data::Inheritable/;
105
f3414019 1061;