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