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