Tatsuhiko Miyagawa's Blog

"Practical" modern Perl for Ruby/Python people

March 19, 2010

“Modern Perl” people usually focus on stuff like Catalyst, Moose and DBIx::Class – they’re awesome modules and Web/ORM thing you should look at, but here’s another take to show off what “recent” perl would look like to Ruby/Python web developers who are familiar with Rack and WSGI.

This is a PSGI application that connects to Twitter streaming API and displays the recent 10 tweets received from the firehose.

It uses some modern tools worth explaining:

PSGI and Plack to abstract web servers (like WSGI and Rack), autobox.pm for autoboxing, Markapl for templating (like Markaby in Camping), AnyEvent for non-blocking event loops (like eventmachine) and Twiggy to run the non-blocking PSGI apps on AnyEvent (like Thin or node.js).

Note for Perl developers: Original script was using perl5i to enable autoboxing, which should make my code slightly more similar to Ruby/Python code where everything is an object, because otherwise they’d pick it up and say “Argh look at that ugly array slicing syntax!” which nukes the entire point of this post. However perl5i has some global side effects to interfere with some AnyEvent code if you’re using perl 5.10.0 - i updated it to use autobox::Core directly.