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=0ed488dcc151966e52127e3287435232b5c3b7dc;hp=bd02b9cbda70087648569d85eeab1349db835e85;hb=5e7e6b272a9e1b8bf1c401dd3a607fc851c43cc7;hpb=0dd88998451d29e841dc3d9484924aa32aa5090c diff --git a/lib/Catalyst/Middleware/Stash.pm b/lib/Catalyst/Middleware/Stash.pm index bd02b9c..0ed488d 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.v2' } 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 { @@ -24,6 +24,7 @@ sub stash { } sub _create_stash { + my $self = shift; my $stash = shift || +{}; return sub { if(@_) { @@ -38,15 +39,11 @@ sub _create_stash { }; } -sub _init_stash_in { - my ($env) = @_; - return $env->{&PSGI_KEY} ||= - _create_stash; -} - sub call { my ($self, $env) = @_; - _init_stash_in($env); + $env->{+PSGI_KEY} = $self->_create_stash + unless exists($env->{+PSGI_KEY}); + return $self->app->($env); } @@ -61,7 +58,18 @@ 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. + +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. =head1 SUBROUTINES @@ -104,7 +112,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