X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FMiddleware%2FStash.pm;h=c8d59451839ff261f655e02cbd4c094be7e89318;hb=cea573d8055680f12b061aa8adcf0b54f576bb7b;hp=4682da8327471b7110770071234465f77743deb9;hpb=566678d0245e49d7f2f1abce553b5bdb87879086;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Middleware/Stash.pm b/lib/Catalyst/Middleware/Stash.pm index 4682da8..c8d5945 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,11 +41,10 @@ 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}); - $new_env->{+PSGI_KEY} = _create_stash( \%stash ); - return $self->app->($new_env); + return $self->app->($env); } =head1 NAME @@ -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 applications. 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.