Remove the fugly hack to avoid metaclass compat issues now that Moose is fixed
[catagits/Catalyst-Runtime.git] / t / lib / TestApp.pm
1 package TestApp;
2
3 use strict;
4 use Catalyst qw/
5     Test::MangleDollarUnderScore
6     Test::Errors 
7     Test::Headers 
8     Test::Plugin
9     Test::Inline
10     +TestApp::Plugin::FullyQualified
11     +TestApp::Plugin::AddDispatchTypes
12     +TestApp::Role
13 /;
14 use Catalyst::Utils;
15
16 use Moose;
17 use namespace::autoclean;
18
19 our $VERSION = '0.01';
20
21 TestApp->config( name => 'TestApp', root => '/some/dir' );
22
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.
26 has an_attribute_before_we_change_base_classes => ( is => 'ro');
27
28 if ($::setup_leakchecker && eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
29     with 'CatalystX::LeakChecker';
30
31     has leaks => (
32         is      => 'ro',
33         default => sub { [] },
34     );
35 }
36
37 sub found_leaks {
38     my ($ctx, @leaks) = @_;
39     push @{ $ctx->leaks }, @leaks;
40 }
41
42 sub count_leaks {
43     my ($ctx) = @_;
44     return scalar @{ $ctx->leaks };
45 }
46
47 TestApp->setup;
48
49 sub execute {
50     my $c      = shift;
51     my $class  = ref( $c->component( $_[0] ) ) || $_[0];
52     my $action = $_[1]->reverse;
53
54     my $method;
55
56     if ( $action =~ /->(\w+)$/ ) {
57         $method = $1;
58     }
59     elsif ( $action =~ /\/(\w+)$/ ) {
60         $method = $1;
61     }
62     elsif ( $action =~ /^(\w+)$/ ) {
63         $method = $action;
64     }
65
66     if ( $class && $method && $method !~ /^_/ ) {
67         my $executed = sprintf( "%s->%s", $class, $method );
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         );
74     }
75     no warnings 'recursion';
76     return $c->SUPER::execute(@_);
77 }
78
79 # Replace the very large HTML error page with
80 # useful info if something crashes during a test
81 sub finalize_error {
82     my $c = shift;
83     
84     $c->next::method(@_);
85     
86     $c->res->status(500);
87     $c->res->body( 'FATAL ERROR: ' . join( ', ', @{ $c->error } ) );
88 }
89
90 {
91     no warnings 'redefine';
92     sub Catalyst::Log::error { }
93 }
94
95 # Make sure we can load Inline plugins. 
96
97 package Catalyst::Plugin::Test::Inline;
98
99 use strict;
100
101 use base qw/Class::Data::Inheritable/;
102
103 1;