Commit | Line | Data |
4b0b7489 |
1 | use warnings; |
2 | use strict; |
3 | |
4 | { |
5 | |
878f6271 |
6 | package MyMiddleware; |
7 | $INC{'MyMiddleware'} = __FILE__; |
8 | |
9 | our $INNER_VAR_EXPOSED; |
10 | |
11 | use base 'Plack::Middleware'; |
12 | |
13 | sub call { |
14 | my ($self, $env) = @_; |
15 | |
16 | my $res = $self->app->($env); |
17 | |
18 | return $self->response_cb($res, sub{ |
19 | my $inner = shift; |
20 | |
21 | $INNER_VAR_EXPOSED = $env->{inner_var_from_catalyst}; |
22 | |
23 | return; |
24 | }); |
25 | |
26 | } |
27 | |
4b0b7489 |
28 | package MyAppChild::Controller::User; |
29 | $INC{'MyAppChild/Controller/User.pm'} = __FILE__; |
30 | |
31 | use base 'Catalyst::Controller'; |
32 | use Test::More; |
33 | |
34 | sub stash :Local { |
35 | my ($self, $c) = @_; |
36 | $c->stash->{inner} = "inner"; |
37 | $c->res->body( "inner: ${\$c->stash->{inner}}, outer: ${\$c->stash->{outer}}"); |
38 | |
878f6271 |
39 | $c->req->env->{inner_var_from_catalyst} = 'station'; |
40 | |
efa13fa4 |
41 | is_deeply [sort {$a cmp $b} keys(%{$c->stash})], ['inner','outer'], 'both keys in stash'; |
4b0b7489 |
42 | } |
43 | |
44 | package MyAppChild; |
45 | $INC{'MyAppChild.pm'} = __FILE__; |
46 | |
47 | use Catalyst; |
48 | MyAppChild->setup; |
49 | |
50 | package MyAppParent::Controller::User; |
51 | $INC{'MyAppParent/Controller/User.pm'} = __FILE__; |
52 | |
53 | use base 'Catalyst::Controller'; |
54 | use Test::More; |
55 | |
56 | sub stash :Local { |
57 | my ($self, $c) = @_; |
58 | $c->stash->{outer} = "outer"; |
59 | $c->res->from_psgi_response( MyAppChild->to_app->($c->req->env) ); |
60 | |
5e7e6b27 |
61 | is_deeply [sort keys(%{$c->stash})], ['inner','outer']; |
4b0b7489 |
62 | } |
63 | |
64 | package MyAppParent; |
65 | use Catalyst; |
5e7e6b27 |
66 | MyAppParent->config(psgi_middleware=>['+MyMiddleware']); |
4b0b7489 |
67 | MyAppParent->setup; |
68 | |
69 | } |
70 | |
71 | use Test::More; |
72 | use Catalyst::Test 'MyAppParent'; |
73 | |
74 | my $res = request '/user/stash'; |
75 | is $res->content, 'inner: inner, outer: outer', 'got expected response'; |
878f6271 |
76 | is $MyMiddleware::INNER_VAR_EXPOSED, 'station', 'env does not get trampled'; |
4b0b7489 |
77 | |
78 | done_testing; |