Dancer is YAPWF (Yet Another Perl Web Framework), in the same bucket as Catalyst. To date I’ve done most of my webapp development on Catalyst, but at the last German Perl Workshop @bano99 introduced me to Dancer, so I wanted to give it a try.
Behind the scenes I have a home built micro-controller web server controlling the temperature in a refrigerator to bring our turtles into a healthy winter hibernation. A perl script regularly (once per minute) queries the current status from the micro-controller, and logs the data (temperature in the tank, the refrigerator, room, humidity, and switch state) to a (SQLite) database. So, I have some interesting data, and want to make that web accessible – how well suited is Dancer to the task?
Turns out: very suitable!
- super quick and easy to get started with: 2 minutes tops to get a basic web application running, including installing Dancer with cpanplus.
- very intuitive for the basic stuff – in my case I had a template for the webpage, a database handler to get the data, and a method to do some basic analysis and pre-processing on the data before returning it to the client as json.
- a bit procedural… it is possible to develop an OOP app with Dancer, but with its background singleton and plethora of new syntax it feels like, and encourages procedural practices.
Dancer is not (IMHO)…
- a framework which will force/cajole you into using good design practices (OOP, MVC). You can be quick’n’dirty with Dancer, which depending on your standpoint can be a pro or a con.
- easy to understand the inner workings. You may hate the global $c in Catalyst to which everything is bound, but … you do know what to bind stuff to, and you do know where to find it. In Dancer there is (even) more hidden magic.
- for special wishes. For example for something as simple as having “Expires” http headers for static files, I had to add a after_file_render hook.
Better, Faster and Cooler
Some other stuff I did on the way to make it BFC:
- Used jqPlot for the graphs. I really like it! I used to be into OFC, but jqPlot is faster, more versatile, and the big kicker: doesn’t require Flash! Try out the zooming and mouse-over effects!
- Data compression: originally the data for the charts weighed in at over 2MB…
- Deflate the data – by using Plack::Middleware::Deflater I was able to further reduce the transmitted data to ~40KB
- Using Plack and Starman to easily put the webapp online. Wow… that makes the transition from development on localhost to full deployment serverside childsplay!
I will definitely be using Dancer again. For any corporate and larger web applications I’d still prefer Catalyst, but for applications like this where I want to put something small online quickly, it’s the bees knees!