Fix unquoted regex as per RT#24951
[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
d9d8aa51 16use Moose;
17use namespace::autoclean;
18
dd4e6fd2 19our $VERSION = '0.01';
20
fbcc39ad 21TestApp->config( name => 'TestApp', root => '/some/dir' );
dd4e6fd2 22
da1c9ff8 23if ($::setup_leakchecker && eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
d9d8aa51 24 with 'CatalystX::LeakChecker';
25
26 has leaks => (
27 is => 'ro',
28 default => sub { [] },
29 );
30}
31
32sub found_leaks {
33 my ($ctx, @leaks) = @_;
34 push @{ $ctx->leaks }, @leaks;
35}
36
37sub count_leaks {
38 my ($ctx) = @_;
39 return scalar @{ $ctx->leaks };
40}
41
dd4e6fd2 42TestApp->setup;
43
dd4e6fd2 44sub execute {
4d989a5d 45 my $c = shift;
46 my $class = ref( $c->component( $_[0] ) ) || $_[0];
f3414019 47 my $action = $_[1]->reverse;
dd4e6fd2 48
49 my $method;
50
4d989a5d 51 if ( $action =~ /->(\w+)$/ ) {
52 $method = $1;
dd4e6fd2 53 }
4d989a5d 54 elsif ( $action =~ /\/(\w+)$/ ) {
55 $method = $1;
dd4e6fd2 56 }
01ba879f 57 elsif ( $action =~ /^(\w+)$/ ) {
58 $method = $action;
59 }
60
ba599d1c 61 if ( $class && $method && $method !~ /^_/ ) {
1408d0a4 62 my $executed = sprintf( "%s->%s", $class, $method );
fbcc39ad 63 my @executed = $c->response->headers->header('X-Catalyst-Executed');
64 push @executed, $executed;
65 $c->response->headers->header(
66 'X-Catalyst-Executed' => join ', ',
67 @executed
68 );
1408d0a4 69 }
81f25ce6 70 no warnings 'recursion';
dd4e6fd2 71 return $c->SUPER::execute(@_);
72}
73
8153c836 74# Replace the very large HTML error page with
75# useful info if something crashes during a test
76sub finalize_error {
77 my $c = shift;
78
dbb2d5cd 79 $c->next::method(@_);
8153c836 80
81 $c->res->status(500);
82 $c->res->body( 'FATAL ERROR: ' . join( ', ', @{ $c->error } ) );
83}
84
369c09bc 85{
86 no warnings 'redefine';
87 sub Catalyst::Log::error { }
88}
4ca147fa 89
90# Make sure we can load Inline plugins.
91
92package Catalyst::Plugin::Test::Inline;
93
94use strict;
95
c057ae86 96use base qw/Class::Data::Inheritable/;
4ca147fa 97
f3414019 981;