Class::MOP::load_class, is_class_loaded was deprecated in Moose-2.1100
[catagits/Catalyst-Runtime.git] / t / lib / TestApp.pm
CommitLineData
dd4e6fd2 1package TestApp;
dd4e6fd2 2use strict;
836e1134 3use Catalyst qw/
3d101ef9 4 Test::MangleDollarUnderScore
836e1134 5 Test::Errors
6 Test::Headers
7 Test::Plugin
4ca147fa 8 Test::Inline
836e1134 9 +TestApp::Plugin::FullyQualified
083ee5d9 10 +TestApp::Plugin::AddDispatchTypes
e5210a95 11 +TestApp::Role
836e1134 12/;
1408d0a4 13use Catalyst::Utils;
e7399d8b 14use Class::Load 'try_load_class';
dd4e6fd2 15
d9d8aa51 16use Moose;
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 }
55046410 53 },
1bef5f59 54 encoding => 'UTF-8',
6e8520be 55 abort_chain_on_error_fix => 1,
bf7c9c87 56);
dd4e6fd2 57
85a351e5 58# Test bug found when re-adjusting the metaclass compat code in Moose
59# in 292360. Test added to Moose in 4b760d6, but leave this attribute
60# above ->setup so we have some generated methods to be double sure.
61has an_attribute_before_we_change_base_classes => ( is => 'ro');
62
e7399d8b 63if ($::setup_leakchecker && try_load_class('CatalystX::LeakChecker')) {
d9d8aa51 64 with 'CatalystX::LeakChecker';
65
66 has leaks => (
67 is => 'ro',
68 default => sub { [] },
69 );
70}
71
72sub found_leaks {
73 my ($ctx, @leaks) = @_;
74 push @{ $ctx->leaks }, @leaks;
75}
76
77sub count_leaks {
78 my ($ctx) = @_;
79 return scalar @{ $ctx->leaks };
80}
81
dd4e6fd2 82TestApp->setup;
83
dd4e6fd2 84sub execute {
4d989a5d 85 my $c = shift;
86 my $class = ref( $c->component( $_[0] ) ) || $_[0];
f3414019 87 my $action = $_[1]->reverse;
dd4e6fd2 88
89 my $method;
90
4d989a5d 91 if ( $action =~ /->(\w+)$/ ) {
92 $method = $1;
dd4e6fd2 93 }
4d989a5d 94 elsif ( $action =~ /\/(\w+)$/ ) {
95 $method = $1;
dd4e6fd2 96 }
01ba879f 97 elsif ( $action =~ /^(\w+)$/ ) {
98 $method = $action;
99 }
100
ba599d1c 101 if ( $class && $method && $method !~ /^_/ ) {
1408d0a4 102 my $executed = sprintf( "%s->%s", $class, $method );
fbcc39ad 103 my @executed = $c->response->headers->header('X-Catalyst-Executed');
104 push @executed, $executed;
105 $c->response->headers->header(
106 'X-Catalyst-Executed' => join ', ',
107 @executed
108 );
1408d0a4 109 }
81f25ce6 110 no warnings 'recursion';
dd4e6fd2 111 return $c->SUPER::execute(@_);
112}
113
8153c836 114# Replace the very large HTML error page with
115# useful info if something crashes during a test
116sub finalize_error {
117 my $c = shift;
118
dbb2d5cd 119 $c->next::method(@_);
8153c836 120
121 $c->res->status(500);
122 $c->res->body( 'FATAL ERROR: ' . join( ', ', @{ $c->error } ) );
123}
124
369c09bc 125{
126 no warnings 'redefine';
127 sub Catalyst::Log::error { }
128}
4ca147fa 129
258733f1 130# Pretend to be Plugin::Session and hook finalize_headers to send a header
131
132sub finalize_headers {
133 my $c = shift;
134
135 $c->res->header('X-Test-Header', 'valid');
136
89ba65d5 137 my $call_count = $c->stash->{finalize_headers_call_count} || 0;
138 $call_count++;
139 $c->stash(finalize_headers_call_count => $call_count);
140 $c->res->header('X-Test-Header-Call-Count' => $call_count);
141
258733f1 142 return $c->maybe::next::method(@_);
143}
144
4ca147fa 145# Make sure we can load Inline plugins.
146
147package Catalyst::Plugin::Test::Inline;
148
149use strict;
150
c057ae86 151use base qw/Class::Data::Inheritable/;
4ca147fa 152
f3414019 1531;