Fixed forward to classes
[catagits/Catalyst-Runtime.git] / t / lib / TestApp.pm
1 package TestApp;
2
3 use strict;
4 use Catalyst qw/Test::Errors Test::Headers Test::Plugin/;
5 use Catalyst::Utils;
6
7 our $VERSION = '0.01';
8
9 TestApp->config( name => 'TestApp', root => '/some/dir' );
10
11 TestApp->setup;
12
13 sub index : Private {
14     my ( $self, $c ) = @_;
15     $c->res->body('root index');
16 }
17
18 sub global_action : Private {
19     my ( $self, $c ) = @_;
20     $c->forward('TestApp::View::Dump::Request');
21 }
22
23 sub execute {
24     my $c      = shift;
25     my $class  = ref( $c->component( $_[0] ) ) || $_[0];
26     my $action = "$_[1]";
27
28     my $method;
29
30     if ( $action =~ /->(\w+)$/ ) {
31         $method = $1;
32     }
33     elsif ( $action =~ /\/(\w+)$/ ) {
34         $method = $1;
35     }
36     elsif ( $action =~ /^(\w+)$/ ) {
37         $method = $action;
38     }
39
40     if ( $class && $method && $method !~ /^_/ ) {
41         my $executed = sprintf( "%s->%s", $class, $method );
42         my @executed = $c->response->headers->header('X-Catalyst-Executed');
43         push @executed, $executed;
44         $c->response->headers->header(
45             'X-Catalyst-Executed' => join ', ',
46             @executed
47         );
48     }
49
50     return $c->SUPER::execute(@_);
51 }
52
53 sub class_forward_test_method {
54     my ( $self, $c ) = @_;
55     $c->response->headers->header( 'X-Class-Forward-Test-Method' => 1 );
56 }
57
58 {
59     no warnings 'redefine';
60     sub Catalyst::Log::error { }
61 }
62 1;