Tatsuhiko Miyagawa's Blog

Middlewares and welcome back to 2002.

October 01, 2009

Our Plack/PSGI website is up at plackperl.org. Yeah, read it like “Black Pearl” :)

MIddlewares

Couple of people have shown interest to Plack and wondered ways to extend PSGI applications or Plack servers by patching them. No, most of the time you don’t need to, and you can just write middlewares. 

So here are some sample Middlewares: RearrangeHeaders that sorts HTTP headers based on “Good Practice” from 199x, SimpleContentFilter that applies regular expression based filters to response body, and RequestResponseWrapper that passes Plack::Request and expects Plack::Response, much like HTTP::Engine. 

Pretty powerful.

Note that this RequestResponseWrapper would lose your “application” compatibility with PSGI though. Your app that takes $req and returns $res is not “PSGI app” anymore. It’d be much simpler you do Plack::Request->new(shift) and then returns $res->finalize in your app and that’s still PSGI compatible. Take the wrapper as a sample anyway.

Mason and MaypoleOn my way home I was thinking which frameworks should be added to the “Supported frameworks” list on our site to be more exciting. I felt a little old but thought of the two big names from pre-Catalyst era, like 2002-4. Mason and Maypole.

So there you go: HTML::Mason::PSGIHandler and Maypole::PSGI. Both uses CGI::PSGI for the easy migration from their CGI equivalent (HTML::Mason::CGIHandler and CGI::Maypole).

Maypole was a little hard to adapt since their list of dispatchers is hardcoded and uses multiple inheritance (injecting @ISA at runtime … yeah, like old Catalyst) and you can see my semi-rants in the source code, but overall it works pretty nice.

So who’s next? Do you have a web framework that can be added to the list?