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