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