Tatsuhiko Miyagawa's PSGI/Plack have been on my mind a lot, lately, as a great example of taking a common problem and solving it in the simplest possible way.
I used Plack today, actually; here was my use case:
- I'd written a 15-line Perl script that, run from the command line, produced JSON output with the coordinates of some photos.
- I wanted to plot those photos on a Google map, and in fact had already written the Javascript to do so, given a copy/paste JSON dump of the output of my script.
- I wanted to connect the Perl script and the Javascript using something other than copy/paste of the JSON output.
Here's what I did: I converted my Perl script into a PSGI app by adding around, oh, 4 lines of Perl code. I then ran that script as a webserver using plackup, and converted my Javascript to pull the JSON data via Ajax (using jQuery) from that webserver.
This was something like 10x easier than writing a CGI script, and probably 100x easier than writing an Apache/mod_perl app. And here's the amazing part: by writing it with PSGI, I wrote both a CGI and Apache/mod_perl app, as well as an app that'd run cleanly in a non-blocking server like Perlbal, since it does no I/O.
This is really good.
This is good.
Posted by: ydnar | October 15, 2009 at 10:22 AM
What's Perl?
Posted by: Andrew Anker | October 15, 2009 at 03:40 PM
With the streaming stuff miyagawa and nothingmuch were working on yesterday, there's some exciting stuff happening regarding doing IO in nonblocking servers. The server end of it is completely portable, although you'll have to pick a way to do your nonblocking IO obviously, and that might limit your choice of backend.
Posted by: twitter.com/frodwith | October 16, 2009 at 08:19 AM
Yeah, I blogged about the nonblocking IO stuff http://bulknews.typepad.com/blog/2009/10/psgiplack-streaming-is-now-complete.html and it's looking really good!
Posted by: miyagawa | October 17, 2009 at 09:01 PM