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