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