X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FMiddleware%2FStash.pm;h=c8d59451839ff261f655e02cbd4c094be7e89318;hp=e31f2d6c99e6634d8207c19381af82e5ca1c8aaa;hb=79fb8f95180a06c51de7f0fde227927b5d864a7f;hpb=6dcc530761473f574ccde956e3a321b1dfb3d27e diff --git a/lib/Catalyst/Middleware/Stash.pm b/lib/Catalyst/Middleware/Stash.pm index e31f2d6..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 @@ -58,13 +58,15 @@ directly since it is likely to move off the Catalyst namespace into a stand alone distribution We store a coderef under the C which can be dereferenced with -key values or nothing to access the underly hashref. +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.