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 {
}
sub _create_stash {
+ my $self = shift;
my $stash = shift || +{};
return sub {
if(@_) {
};
}
-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);
}
-=head1 TITLE
+=head1 NAME
Catalyst::Middleware::Stash - The Catalyst stash - in middleware
alone distribution
We store a coderef under the C<PSGI_KEY> 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 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.
=head1 SUBROUTINES
["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