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