Don't run the moose controller test if Moose isn't available
[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
9bfaf006 79sub class_go_test_method :Private {
80 my ( $self, $c ) = @_;
81 $c->response->headers->header( 'X-Class-Go-Test-Method' => 1 );
82}
83
f9bcc128 84sub class_visit_test_method :Private {
85 my ( $self, $c ) = @_;
86 $c->response->headers->header( 'X-Class-Visit-Test-Method' => 1 );
87}
88
1627551a 89sub loop_test : Local {
90 my ( $self, $c ) = @_;
91
92 for( 1..1001 ) {
93 $c->forward( 'class_forward_test_method' );
94 }
95}
96
97sub recursion_test : Local {
98 my ( $self, $c ) = @_;
99 $c->forward( 'recursion_test' );
100}
101
369c09bc 102{
103 no warnings 'redefine';
104 sub Catalyst::Log::error { }
105}
4ca147fa 106
107# Make sure we can load Inline plugins.
108
109package Catalyst::Plugin::Test::Inline;
110
111use strict;
112
113use base qw/Catalyst::Base Class::Data::Inheritable/;
114
9bfaf006 1151;