resolve conflict
John Napiorkowski [Mon, 24 Aug 2015 15:24:08 +0000 (10:24 -0500)]
Changes
lib/Catalyst/Middleware/Stash.pm
t/middleware-stash.t

diff --git a/Changes b/Changes
index 64693c0..61c4c79 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@
   - Document using namespace::autoclean with controllers that have actions
     with type constraints.
   - Look for type constraints in super classes and consumed roles.
+  - Change the way the stash middleware works to no longer localize $psgi_env.
 
 5.90098 - 2015-08-11
   - Fix for RT#106373 (Issue when you try to install and also have an old
index 4682da8..f874810 100644 (file)
@@ -43,8 +43,8 @@ sub call {
   my $new_env = +{ %$env };
   my %stash = %{ ($env->{+PSGI_KEY} || sub {})->() || +{} };
 
-  $new_env->{+PSGI_KEY} = _create_stash( \%stash  );
-  return $self->app->($new_env);
+  $env->{+PSGI_KEY} = _create_stash( \%stash  );
+  return $self->app->($env);
 }
 
 =head1 NAME
index baeb108..24b95f2 100644 (file)
@@ -3,6 +3,28 @@ use strict;
 
 {
 
+  package MyMiddleware;
+  $INC{'MyMiddleware'} = __FILE__;
+
+  our $INNER_VAR_EXPOSED;
+
+  use base 'Plack::Middleware';
+
+  sub call {
+    my ($self, $env) = @_;
+
+    my $res = $self->app->($env);
+
+    return $self->response_cb($res, sub{
+      my $inner = shift;
+
+      $INNER_VAR_EXPOSED = $env->{inner_var_from_catalyst};
+
+      return;
+    });
+
+  }
+
   package MyAppChild::Controller::User;
   $INC{'MyAppChild/Controller/User.pm'} = __FILE__;
 
@@ -14,6 +36,8 @@ use strict;
     $c->stash->{inner} = "inner";
     $c->res->body( "inner: ${\$c->stash->{inner}}, outer: ${\$c->stash->{outer}}");
 
+    $c->req->env->{inner_var_from_catalyst} = 'station';
+
     is_deeply [sort {$a cmp $b} keys(%{$c->stash})], ['inner','outer'], 'both keys in stash';
   }
 
@@ -48,5 +72,6 @@ use Catalyst::Test 'MyAppParent';
 
 my $res = request '/user/stash';
 is $res->content, 'inner: inner, outer: outer', 'got expected response';
+is $MyMiddleware::INNER_VAR_EXPOSED, 'station', 'env does not get trampled';
 
 done_testing;