Cataly...::Stash(3pm)

πŸ“¦
version 5.90132 Β· 6 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Catalyst::Middleware::Stash β€” the Catalyst stash, but make it middleware πŸ’–

okay bestie, so this is Catalyst::Middleware::Stash, a lil Perl module, and it lives in the User Contributed Perl Documentation section of the manual (that's the 3pm part, iykyk). Buckle up, it's short but it's important.


✨ NAME ✨

Catalyst::Middleware::Stash β€” the Catalyst stash, except it's in middleware now. slay. πŸ‘‘


🌸 DESCRIPTION 🌸

So here's the tea: we moved the Catalyst stash into middleware. πŸ’…

Please do NOT use this directly, because it is likely to move off the Catalyst namespace into a stand alone distribution. it's giving "temporary housing situation". πŸ™ˆ

We store a coderef under the PSGI_KEY which can be dereferenced with key values β€” or with nothing β€” to access the underlying hashref. cute, right?

Anything you place 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. And non-Catalyst applications can use this middleware to access and set stash values too. equal opportunity stash access, we love to see it. 🫢

Please note: I highly recommend having a stronger interface than a stash key between applications. fr fr. a stash key is not a personality, it's not an API contract. 😭

And for more information? the current test case t/middleware-stash.t is the best documentation. iconic behavior honestly. that's the real manual. πŸ“–βœ¨


πŸ¦‹ SUBROUTINES πŸ¦‹

This class defines the following subroutines. let's goooo.

πŸŽ€ PSGI_KEY

Returns the hash key where we store the stash.

You should NOT assume the string value here will never change! it can change, bestie, don't build your whole life on it. 😀

Also, it's better to use get_stash or stash. those are the good ones. πŸ’–

πŸŽ€ get_stash

Expect: $psgi_env.

Exportable subroutine.

Get the stash out of the $env. that's it, that's the whole job. ✨

πŸŽ€ stash

Expects: An object that does env and arguments.

Exportable subroutine.

Given an object with a method env, get or set stash values β€” either as a method or via hashref modification. This stash is automatically reset for each request (it is not persistent or shared across connected clients. Stash key / value are stored in memory. πŸ”₯)

use Plack::Request;
use Catalyst::Middleware::Stash 'stash';

my $app = sub {
  my $env = shift;
  my $req = Plack::Request->new($env);
  my $stashed = $req->stash->{in_the_stash};  # Assume the stash was previously populated.

  return [200, ['Content-Type' => 'text/plain'],
    ["I found $stashed in the stash!"]];
};
If the stash does not yet exist, an exception is thrown. no stash? no vibes. exception. πŸ’€

🌈 METHODS 🌈

This class defines the following methods.

🧚 call

Used by plack to call the middleware. that's the whole description. short king. πŸ‘‘


okay that's the whole page bestie, we ate and left no crumbs πŸ“

this was brought to you by perl v5.40.0, dated 2024-11-15, and yeah the header/footer both say Cataly...::Stash(3pm) because the terminal clipped it like it clips my dreams. πŸ’œ byeeee πŸ¦‹πŸŽ€πŸ’…

πŸ“¦ where this page comes from