Dancing Your Way into EffortLess Web Development with Dancer and Perl

Posted by feydr | Posted in Uncategorized | Posted on 26-05-2010

View Comments

Sentiments found on hackernews and dzone recently regarding Perl:

“fuck a bunch of perl monk motherfuckers!”

“perl sucks!”

“perl can suck a dick!”

ok, well that was slightly exagerrated =)

but .. so seems the sentiment sometimes browsing certain portions of the net
(dzone, hackernews, etc.)

Really, imo perl was one of the first dynamic interpreted languages that a LOT of people
got on board with and really opened the door to web development… say what
you want but perl was the “first web language”™

Dancer

A couple of weeks I ran into dancer. I was really quite interested because it’s cousin,
sinatra from rubyland is my favorite framework from that language.

I have to admit that I have not used perl for a while but I had dancer up and tapping it’s toes
within minutes and it is pretty damn fast.

can I sum it up?
yes …. dancer turns perl web development from this…


perl


into this…


marlboros camel

installing

feydr@mhu:~$ sudo cpan Dancer

cpan will block when it’s dling new modules so make sure to pay attn to any visual beeps if you are in screen or something, or you could always use expect or whatever

Sample Hello World written in Dancer

#!/usr/bin/perl
 
use Dancer;
 
get '/hi' => sub {
  "Hello World!"
};
 
dance;
feydr@mhu:~$ perl ./hi.pl

hit it up at: http://127.0.0.1:3000/hi

Some Slightly Drunken Made Benchmarks:
That last red bar should be at 672 request/second.



need some more example code? check out the dancer website source built using dancer

Deploying Dancer into Production

I’d avoid abusing this ass-rocking software with something as terrible as apache as you just won’t get the same performance and you’ll have to do stupid CGI/FastCGI tricks. However, if you must use apache (because you are already using it for 10 other websites on the same box) then you can still use PSGI.

Dancer runs best under PSGI/PLACK

Wait! What the fuck is that shit? PSGI is a spec akin to Python’s WSGI while PLACK is to ruby’s Rack.

confused? just use Starman!!Perl Reference

StarMan Features

  • preforking web server that reaps dead kids and does auto restarts
  • can utilize unix sockets
  • very little memory footprint (like 7-12 meg little)
  • No Win32 Support, yes this is a feature

It’s also written by Japanese hackers. I don’t think I need to mention why Japanese hackers rock..

Yukihiro Matsumoto

back to dancer…

supported session engines by default:

  • memory (no persistence — useful for debugging)
  • yaml file-based (puke!)
  • memcached (distributed production env ftw!)
  • cookie (make sure you protect your shit from timing attacks)

other features:

  • wilcard routing path matching
  • before filters

In comparison to Catalyst? Well, the most obvious is that Dancer is light-weight — like cheerleader on prom night light-weight.

In Closing

For my next ‘small’ project this will probably be written with Dancer rather than Sinatra.
Yes, the terse syntax of perl might not meet the eloquence of ruby but for memory usage
Dancer will win hands down everytime.

blog comments powered by Disqus