From: John Napiorkowski Date: Mon, 24 Aug 2015 16:05:03 +0000 (-0500) Subject: fix issues with middleware stash localizing stuff X-Git-Tag: 5.90100~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=5e7e6b272a9e1b8bf1c401dd3a607fc851c43cc7 fix issues with middleware stash localizing stuff --- diff --git a/Changes b/Changes index 61c4c79..ecd3bca 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,12 @@ # This file documents the revision history for Perl extension Catalyst. -5.90099 - 2015-08-XX +5.90100 - 2015-08-24 - 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. + - If you delegate control to a sub Catalyst application, that application + may now return information to the parent application via the stash. 5.90098 - 2015-08-11 - Fix for RT#106373 (Issue when you try to install and also have an old diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 574ee01..9b41885 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -180,7 +180,7 @@ sub composed_stats_class { __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90098'; +our $VERSION = '5.90100'; $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases sub import { diff --git a/lib/Catalyst/Delta.pod b/lib/Catalyst/Delta.pod index 8ae07c7..7959a6e 100755 --- a/lib/Catalyst/Delta.pod +++ b/lib/Catalyst/Delta.pod @@ -7,6 +7,24 @@ Catalyst::Delta - Overview of changes between versions of Catalyst This is an overview of the user-visible changes to Catalyst between major Catalyst releases. +=head2 VERSION 5.90100 + +Support for type constraints in Args and CaptureArgs has been improved. You may +now inherit from a base controller that declares type constraints and use roles +that declare type constraints. See L for more. + +You may now. also use a full type constraint namespace instead of inporting type +constraints into your package namespace. + +We changed the way the middleware stash works so that it no longer localizes +the PSGI env hashref. This was done to fix bugs where people set PSGI ENV hash +keys and found them to dissappear in certain cases. It also means that now if +a sub applications sets stash variables, that stash will now bubble up to the +parent application. This may be a breaking change for you since previous +versions of this code did not allow that. A workaround is to explicitly delete +stash keys in your sub application before returning control to the parent +application. + =head2 VERSION 5.90097 =head3 Defined how $c->uri_for adds a URI fragment. diff --git a/lib/Catalyst/Middleware/Stash.pm b/lib/Catalyst/Middleware/Stash.pm index f874810..0ed488d 100644 --- a/lib/Catalyst/Middleware/Stash.pm +++ b/lib/Catalyst/Middleware/Stash.pm @@ -9,7 +9,7 @@ use Carp 'croak'; our @EXPORT_OK = qw(stash get_stash); -sub PSGI_KEY () { 'Catalyst.Stash.v1' } +sub PSGI_KEY () { 'Catalyst.Stash.v2' } sub get_stash { my $env = shift; @@ -24,6 +24,7 @@ sub stash { } sub _create_stash { + my $self = shift; my $stash = shift || +{}; return sub { if(@_) { @@ -40,10 +41,9 @@ sub _create_stash { sub call { my ($self, $env) = @_; - my $new_env = +{ %$env }; - my %stash = %{ ($env->{+PSGI_KEY} || sub {})->() || +{} }; + $env->{+PSGI_KEY} = $self->_create_stash + unless exists($env->{+PSGI_KEY}); - $env->{+PSGI_KEY} = _create_stash( \%stash ); return $self->app->($env); } @@ -60,11 +60,13 @@ alone distribution We store a coderef under the C which can be dereferenced with key values or nothing to access the underlying hashref. -The stash middleware is designed so that you can 'nest' applications that -use it. If for example you have a L application that is called -by a controller under a parent L application, the child application -will inherit the full stash of the parent BUT any new keys added by the child -will NOT bubble back up to the parent. However, children of children will. +Anything placed into the stash will be available in the stash of any 'mounted' +Catalyst applictions. A mounted Catalyst application may set the stash and +'pass back' information to the parent application. Non Catalyst applications +may use this middleware to access and set stash values. + +Please note I highly recommend having a stronger interface than a stash key +between applications. For more information the current test case t/middleware-stash.t is the best documentation. diff --git a/lib/Catalyst/Runtime.pm b/lib/Catalyst/Runtime.pm index 80b56c2..a801245 100644 --- a/lib/Catalyst/Runtime.pm +++ b/lib/Catalyst/Runtime.pm @@ -7,7 +7,7 @@ BEGIN { require 5.008003; } # Remember to update this in Catalyst as well! -our $VERSION = '5.90098'; +our $VERSION = '5.90100'; $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases =head1 NAME diff --git a/lib/Catalyst/Upgrading.pod b/lib/Catalyst/Upgrading.pod index 487787a..432e3d0 100644 --- a/lib/Catalyst/Upgrading.pod +++ b/lib/Catalyst/Upgrading.pod @@ -2,6 +2,17 @@ Catalyst::Upgrading - Instructions for upgrading to the latest Catalyst +=head1 Upgrading to Catalyst 5.90100 + +We changed the way the middleware stash works so that it no longer localizes +the PSGI env hashref. This was done to fix bugs where people set PSGI ENV hash +keys and found them to dissappear in certain cases. It also means that now if +a sub applications sets stash variables, that stash will now bubble up to the +parent application. This may be a breaking change for you since previous +versions of this code did not allow that. A workaround is to explicitly delete +stash keys in your sub application before returning control to the parent +application. + =head1 Upgrading to Catalyst 5.90097 In older versions of Catalyst one could construct a L with a fragment (such as diff --git a/t/middleware-stash.t b/t/middleware-stash.t index 24b95f2..dc22ab6 100644 --- a/t/middleware-stash.t +++ b/t/middleware-stash.t @@ -58,11 +58,12 @@ use strict; $c->stash->{outer} = "outer"; $c->res->from_psgi_response( MyAppChild->to_app->($c->req->env) ); - is_deeply [keys(%{$c->stash})], ['outer'], 'only one key in stash'; + is_deeply [sort keys(%{$c->stash})], ['inner','outer']; } package MyAppParent; use Catalyst; + MyAppParent->config(psgi_middleware=>['+MyMiddleware']); MyAppParent->setup; }