Remove the fugly hack to avoid metaclass compat issues now that Moose is fixed
[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
85a351e5 23# Test bug found when re-adjusting the metaclass compat code in Moose
24# in 292360. Test added to Moose in 4b760d6, but leave this attribute
25# above ->setup so we have some generated methods to be double sure.
26has an_attribute_before_we_change_base_classes => ( is => 'ro');
27
da1c9ff8 28if ($::setup_leakchecker && eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
d9d8aa51 29 with 'CatalystX::LeakChecker';
30
31 has leaks => (
32 is => 'ro',
33 default => sub { [] },
34 );
35}
36
37sub found_leaks {
38 my ($ctx, @leaks) = @_;
39 push @{ $ctx->leaks }, @leaks;
40}
41
42sub count_leaks {
43 my ($ctx) = @_;
44 return scalar @{ $ctx->leaks };
45}
46
dd4e6fd2 47TestApp->setup;
48
dd4e6fd2 49sub execute {
4d989a5d 50 my $c = shift;
51 my $class = ref( $c->component( $_[0] ) ) || $_[0];
f3414019 52 my $action = $_[1]->reverse;
dd4e6fd2 53
54 my $method;
55
4d989a5d 56 if ( $action =~ /->(\w+)$/ ) {
57 $method = $1;
dd4e6fd2 58 }
4d989a5d 59 elsif ( $action =~ /\/(\w+)$/ ) {
60 $method = $1;
dd4e6fd2 61 }
01ba879f 62 elsif ( $action =~ /^(\w+)$/ ) {
63 $method = $action;
64 }
65
ba599d1c 66 if ( $class && $method && $method !~ /^_/ ) {
1408d0a4 67 my $executed = sprintf( "%s->%s", $class, $method );
fbcc39ad 68 my @executed = $c->response->headers->header('X-Catalyst-Executed');
69 push @executed, $executed;
70 $c->response->headers->header(
71 'X-Catalyst-Executed' => join ', ',
72 @executed
73 );
1408d0a4 74 }
81f25ce6 75 no warnings 'recursion';
dd4e6fd2 76 return $c->SUPER::execute(@_);
77}
78
8153c836 79# Replace the very large HTML error page with
80# useful info if something crashes during a test
81sub finalize_error {
82 my $c = shift;
83
dbb2d5cd 84 $c->next::method(@_);
8153c836 85
86 $c->res->status(500);
87 $c->res->body( 'FATAL ERROR: ' . join( ', ', @{ $c->error } ) );
88}
89
369c09bc 90{
91 no warnings 'redefine';
92 sub Catalyst::Log::error { }
93}
4ca147fa 94
95# Make sure we can load Inline plugins.
96
97package Catalyst::Plugin::Test::Inline;
98
99use strict;
100
c057ae86 101use base qw/Class::Data::Inheritable/;
4ca147fa 102
f3414019 1031;