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