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;fp=lib%2FCatalyst%2FMiddleware%2FStash.pm;h=e31f2d6c99e6634d8207c19381af82e5ca1c8aaa;hp=bd02b9cbda70087648569d85eeab1349db835e85;hb=6dcc530761473f574ccde956e3a321b1dfb3d27e;hpb=e4f3fb2485c9181600ca8fe759016f9e69a53f2d diff --git a/lib/Catalyst/Middleware/Stash.pm b/lib/Catalyst/Middleware/Stash.pm index bd02b9c..e31f2d6 100644 --- a/lib/Catalyst/Middleware/Stash.pm +++ b/lib/Catalyst/Middleware/Stash.pm @@ -9,12 +9,12 @@ use Carp 'croak'; our @EXPORT_OK = qw(stash get_stash); -sub PSGI_KEY { 'Catalyst.Stash.v1' }; +sub PSGI_KEY () { 'Catalyst.Stash.v1' } sub get_stash { my $env = shift; - return $env->{&PSGI_KEY} || - _init_stash_in($env); + return $env->{+PSGI_KEY} || + croak "You requested a stash, but one does not exist."; } sub stash { @@ -38,16 +38,13 @@ sub _create_stash { }; } -sub _init_stash_in { - my ($env) = @_; - return $env->{&PSGI_KEY} ||= - _create_stash; -} - sub call { my ($self, $env) = @_; - _init_stash_in($env); - return $self->app->($env); + my $new_env = +{ %$env }; + my %stash = %{ ($env->{+PSGI_KEY} || sub {})->() || +{} }; + + $new_env->{+PSGI_KEY} = _create_stash( \%stash ); + return $self->app->($new_env); } =head1 NAME @@ -63,6 +60,15 @@ alone distribution We store a coderef under the C which can be dereferenced with key values or nothing to access the underly 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. + +For more information the current test case t/middleware-stash.t is the best +documentation. + =head1 SUBROUTINES This class defines the following subroutines. @@ -104,7 +110,7 @@ clients. Stash key / value are stored in memory. ["I found $stashed in the stash!"]]; }; -If the stash does not yet exist, we initialize one and return that. +If the stash does not yet exist, an exception is thrown. =head1 METHODS