error is now in Context (t/aggregate/live_recursion.t and others)
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Context.pm
CommitLineData
fdcc808c 1package TestApp::Context;
2use Moose;
3extends 'Catalyst::Context';
04f7e630 4with 'Catalyst::TraitFor::Context::TestHeaders';
0e74c6cd 5with 'Catalyst::TraitFor::Context::TestErrors';
fdcc808c 6
7if (eval { Class::MOP::load_class('CatalystX::LeakChecker'); 1 }) {
8 with 'CatalystX::LeakChecker';
9
10 has leaks => (
11 is => 'ro',
12 default => sub { [] },
13 );
14}
15
16sub found_leaks {
17 my ($ctx, @leaks) = @_;
18 push @{ $ctx->leaks }, @leaks;
19}
20
21sub count_leaks {
22 my ($ctx) = @_;
23 return scalar @{ $ctx->leaks };
24}
25
6d136e07 26sub execute {
27 my $c = shift;
28 my $class = ref( $c->component( $_[0] ) ) || $_[0];
29 my $action = $_[1]->reverse;
30
31 my $method;
32
33 if ( $action =~ /->(\w+)$/ ) {
34 $method = $1;
35 }
36 elsif ( $action =~ /\/(\w+)$/ ) {
37 $method = $1;
38 }
39 elsif ( $action =~ /^(\w+)$/ ) {
40 $method = $action;
41 }
42
43 if ( $class && $method && $method !~ /^_/ ) {
44 my $executed = sprintf( "%s->%s", $class, $method );
45 my @executed = $c->response->headers->header('X-Catalyst-Executed');
46 push @executed, $executed;
47 $c->response->headers->header(
48 'X-Catalyst-Executed' => join ', ',
49 @executed
50 );
51 }
52 no warnings 'recursion';
53 return $c->SUPER::execute(@_);
54}
55
fdcc808c 561;
57