Developer ports middleware stack to PAGI, Perl's async ASGI-style interface
A developer has ported a three-layer middleware demonstration app to PAGI, an async ASGI-style application interface for Perl, previously implemented in Plack/PSGI and Starlette/ASGI. The sample stack includes three middleware components: a Logger that times and records requests, an Authenticator that validates headers and short-circuits with a 401 on failure, and a ProfileRouter that serves a specific route using injected context. In PAGI, a middleware is a subroutine that accepts an application and returns a new one wrapping the inner app, mirroring the ASGI contract of a coderef over scope, receive, and send. The convenience layer PAGI::Middleware::Builder adds helpers like modify_scope and intercept_send, enabling context injection without global mutation by shallow-copying the scope hash. All code was verified under perl-5.40.0 using PAGI::Test::Client, with log output reflecting actual captured results.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in