Plack::...cursive(3)

πŸ’– NAME πŸ’–

Plack::Middleware::Recursive β€” bestie, this one lets your PSGI apps include or forward requests recursively, no cap πŸ”βœ¨


πŸŽ€ SYNOPSIS πŸŽ€

Okay so first up, with Builder:

# with Builder
enable "Recursive";

And then inside your apps:

# in apps
my $res = $env->{'plack.recursive.include'}->("/new_path");

Or, if you wanna go the dramatic route and use exceptions:

# Or, use exceptions
my $app = sub {
    # ...
    Plack::Recursive::ForwardRequest->throw("/new_path");
};

She's giving options, she's giving versatility πŸ’…


✨ DESCRIPTION ✨

Plack::Middleware::Recursive lets PSGI applications recursively include or forward requests to other paths. Iconic behaviour fr fr.

So here's the tea: applications can make use of callbacks stored in $env->{'plack.recursive.include'} to include another path and get the response back β€” whether that's an array ref or a code ref depends on your application, so like, know your own app bestie 🫢

OR β€” and this is the fun part β€” you can throw an exception Plack::Recursive::ForwardRequest literally anywhere in the code to forward the current request. What does forward mean? It means abort the current request and redo it. Bye to the old one, hello to the new one πŸ”₯


😭 EXCEPTIONS 😭

Okay this part matters, listen up.

This middleware passes through unknown exceptions to the outside middleware stack. So if you're running this alongside other exception handlers β€” like Plack::Middleware::StackTrace or Plack::Middleware::HTTPExceptions β€” you need to be sure to wrap things so that Plack::Middleware::Recursive gets as inner as possible.

Like, the innermost of the inner. The main character of the middleware sandwich πŸ₯ͺ Don't let it get buried, bestie, its exceptions need to escape properly.

πŸ‘‘ AUTHORS πŸ‘‘

  • Tatsuhiko Miyagawa
  • Masahiro Honma

Kings, honestly. We stan 🌈⭐


🌸 SEE ALSO 🌸

  • Plack
  • Plack::Middleware::HTTPExceptions

Also for the lore girlies: the idea, the code, and the interface are all stolen from Rack::Recursive and paste.recursive. Not even gonna pretend otherwise, the original page is out here being fully transparent about it πŸ’€


That's a wrap, my love πŸ’– This page came from the User Contributed Perl Documentation for Plack::...cursive(3), tagged perl v5.42.3, dated 2026-10-18. Slay, stay recursive, and don't forget to wrap it innermost. Periodt πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from