7 $INC{'MyMiddleware'} = __FILE__;
9 our $INNER_VAR_EXPOSED;
11 use base 'Plack::Middleware';
14 my ($self, $env) = @_;
16 my $res = $self->app->($env);
18 return $self->response_cb($res, sub{
21 $INNER_VAR_EXPOSED = $env->{inner_var_from_catalyst};
28 package MyAppChild::Controller::User;
29 $INC{'MyAppChild/Controller/User.pm'} = __FILE__;
31 use base 'Catalyst::Controller';
36 $c->stash->{inner} = "inner";
37 $c->res->body( "inner: ${\$c->stash->{inner}}, outer: ${\$c->stash->{outer}}");
39 $c->req->env->{inner_var_from_catalyst} = 'station';
41 is_deeply [sort {$a cmp $b} keys(%{$c->stash})], ['inner','outer'], 'both keys in stash';
45 $INC{'MyAppChild.pm'} = __FILE__;
50 package MyAppParent::Controller::User;
51 $INC{'MyAppParent/Controller/User.pm'} = __FILE__;
53 use base 'Catalyst::Controller';
58 $c->stash->{outer} = "outer";
59 $c->res->from_psgi_response( MyAppChild->to_app->($c->req->env) );
61 is_deeply [sort keys(%{$c->stash})], ['inner','outer'];
66 MyAppParent->config(psgi_middleware=>['+MyMiddleware']);
72 use Catalyst::Test 'MyAppParent';
74 my $res = request '/user/stash';
75 is $res->content, 'inner: inner, outer: outer', 'got expected response';
76 is $MyMiddleware::INNER_VAR_EXPOSED, 'station', 'env does not get trampled';