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