Dancer 1.150 released – a flexible, lightweight web framework for Perl

Version 1.150 of the Dancer web framework has just been released, so this seemed like a good time to write up this post.

Recently, I’ve been wanting to find a Perl web framework that I really got on with. I’ve used Catalyst, which is very powerful and popular, but it’s quite heavy (a lot of dependencies, and reasonably high memory usage and startup time), and I felt as though it forced me to code “the Catalyst way”, rather than staying out of my way and getting on with writing my code.

I took a look around at the current Perl web frameworks (e.g. CGI-Application, Jifty, Catalyst, Mojo…) – all good in their own ways, but for various reasons, none of them really struck me as something I’d be particularly happy to work with.

I did briefly consider trying to write my own, but that’s a wheel I do not want to re-invent – there’s enough odd-shaped wheels out there already.

When I found Dancer (a port of Ruby’s Sinatra framework), I immediately liked the fact it looked simple and stays out of the way as much as possible, so I gave it a try – and, I must say, I’m impressed.

It’s simple to use yet lets you do powerful things, and lets me just get on with coding my web app without getting in the way or making me think too much. The interface just seems to make sense – intuitive guesses as to how something will work were often proved correct :)

The new Dancer::Cookbook">Dancer Cookbook includes many code samples illustrating Dancer in action, but the following is a fully-working Dancer web application:

    #!/usr/bin/perl
    use Dancer;
    get '/hello/:name' => sub {
        return "Why, hello there " . params->{name};
    };
    dance;

(No need to use strict – Dancer does that for you.)

There were a few improvements I thought needed making, in particularly the documentation, so I approached the author Alexis Sukrieh on IRC, forked the Dancer Github repository, and started hacking on the code; several of my improvements are in 1.150, and I’ve found Alexis and the other developers to be approachable, decent developers – it’s great to see the power of Open Source at work :)

Despite its lightweight approach, Dancer includes a very friendly error display page enabled for the development environment (but obviously disabled for production, as it’d look unprofessional, and more importantly, could leak sensitive information).

Here’s a screenshot of the error page:

route-handler-error-page-1

Benchmarks

Just for fun, I tried a couple of very basic Benchmarks to compare Dancer and Catalyst, and found Dancer to be 526% quicker at initial startup, and used 56.76% less RAM. These were obtained using e.g. time perl -MDancer -e0, and are very basic; YMMV.

I also did brief load testing with openload, and with 100 simultaneous clients making requests, a basic standalone Dancer app satisified around 250 requests per second – not too shabby.

Anyway, I’ve found Dancer to be very promising, it’s already my choice of web framework, and it’s nice to know that in the true spirit of open source, if I think something can be improved, I can submit those improvements.

4 thoughts on “Dancer 1.150 released – a flexible, lightweight web framework for Perl”

Comments are closed.