fixing merge conflicts from master
[catagits/Catalyst-Runtime.git] / t / lib / TestApp.pm
CommitLineData
dd4e6fd2 1package TestApp;
f328387a 2use Moose;
dd4e6fd2 3
836e1134 4use Catalyst qw/
3d101ef9 5 Test::MangleDollarUnderScore
3328bcb3 6 Test::Errors
7 Test::Headers
836e1134 8 Test::Plugin
4ca147fa 9 Test::Inline
836e1134 10 +TestApp::Plugin::FullyQualified
083ee5d9 11 +TestApp::Plugin::AddDispatchTypes
e5210a95 12 +TestApp::Role
836e1134 13/;
f328387a 14extends 'Catalyst';
1408d0a4 15use Catalyst::Utils;
dd4e6fd2 16
d9d8aa51 17use namespace::autoclean;
18
950c7852 19# -----------
20# t/aggregate/unit_core_ctx_attr.t pukes until lazy is true
21package Greeting;
22use Moose;
23sub hello_notlazy { 'hello there' }
24sub hello_lazy { 'hello there' }
25
26package TestApp;
27has 'my_greeting_obj_notlazy' => (
28 is => 'ro',
29 isa => 'Greeting',
30 default => sub { Greeting->new() },
31 handles => [ qw( hello_notlazy ) ],
32 lazy => 0,
33);
34has 'my_greeting_obj_lazy' => (
35 is => 'ro',
36 isa => 'Greeting',
37 default => sub { Greeting->new() },
38 handles => [ qw( hello_lazy ) ],
39 lazy => 1,
40);
41# -----------
42
dd4e6fd2 43our $VERSION = '0.01';
44
bf7c9c87 45TestApp->config(
46 name => 'TestApp',
47 root => '/some/dir',
48 use_request_uri_for_path => 1,
49 'Controller::Action::Action' => {
50 action_args => {
51 action_action_nine => { another_extra_arg => 13 }
52 }
53 }
54);
dd4e6fd2 55
85a351e5 56# Test bug found when re-adjusting the metaclass compat code in Moose
57# in 292360. Test added to Moose in 4b760d6, but leave this attribute
58# above ->setup so we have some generated methods to be double sure.
59has an_attribute_before_we_change_base_classes => ( is => 'ro');
60
da1c9ff8 61if ($::setup_leakchecker && eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
d9d8aa51 62 with 'CatalystX::LeakChecker';
63
64 has leaks => (
65 is => 'ro',
66 default => sub { [] },
67 );
68}
69
70sub found_leaks {
71 my ($ctx, @leaks) = @_;
72 push @{ $ctx->leaks }, @leaks;
73}
74
75sub count_leaks {
76 my ($ctx) = @_;
77 return scalar @{ $ctx->leaks };
78}
79
dd4e6fd2 80TestApp->setup;
81
dd4e6fd2 82sub execute {
4d989a5d 83 my $c = shift;
84 my $class = ref( $c->component( $_[0] ) ) || $_[0];
f3414019 85 my $action = $_[1]->reverse;
dd4e6fd2 86
87 my $method;
88
4d989a5d 89 if ( $action =~ /->(\w+)$/ ) {
90 $method = $1;
dd4e6fd2 91 }
4d989a5d 92 elsif ( $action =~ /\/(\w+)$/ ) {
93 $method = $1;
dd4e6fd2 94 }
01ba879f 95 elsif ( $action =~ /^(\w+)$/ ) {
96 $method = $action;
97 }
98
ba599d1c 99 if ( $class && $method && $method !~ /^_/ ) {
1408d0a4 100 my $executed = sprintf( "%s->%s", $class, $method );
fbcc39ad 101 my @executed = $c->response->headers->header('X-Catalyst-Executed');
102 push @executed, $executed;
103 $c->response->headers->header(
104 'X-Catalyst-Executed' => join ', ',
105 @executed
106 );
1408d0a4 107 }
81f25ce6 108 no warnings 'recursion';
dd4e6fd2 109 return $c->SUPER::execute(@_);
110}
111
8153c836 112# Replace the very large HTML error page with
113# useful info if something crashes during a test
114sub finalize_error {
115 my $c = shift;
3328bcb3 116
dbb2d5cd 117 $c->next::method(@_);
3328bcb3 118
8153c836 119 $c->res->status(500);
120 $c->res->body( 'FATAL ERROR: ' . join( ', ', @{ $c->error } ) );
121}
122
369c09bc 123{
124 no warnings 'redefine';
125 sub Catalyst::Log::error { }
126}
4ca147fa 127
258733f1 128# Pretend to be Plugin::Session and hook finalize_headers to send a header
129
130sub finalize_headers {
131 my $c = shift;
132
133 $c->res->header('X-Test-Header', 'valid');
134
135 return $c->maybe::next::method(@_);
136}
137
6ac0784b 138# Make sure we can load Inline plugins.
4ca147fa 139
140package Catalyst::Plugin::Test::Inline;
141
142use strict;
143
c057ae86 144use base qw/Class::Data::Inheritable/;
4ca147fa 145
f3414019 1461;