Installing Dancer, a perl web framework, on Debian Wheezy

February 19, 2011

This post is going to describe what I did to get Dancer up and running on Debian Wheezy. Dancer is a web development framework and as such aims to help you develop web applications more quickly. Dancer also supports psgi, or “Plack”, which is a tool to glue together your web application with your web server, making the two more interchangeable. Contrast this with mod_perl for example which is tightly coupled to the Apache web server.

I use Debian Testing (codename Wheezy) on my workstation at home, but Dancer is not yet available for Debian Testing although it should be showing up in testing in a day or two. I’m going to drop into a sid chroot to install Dancer since it isn’t in testing. A sid chroot is a chrooted version of Debian which is very useful for testing and writing software. A chroot essentially creates a separate root file system and encloses that root file system in a separate directory. If something goes wrong in this separate root file system it often has no impact on the other parts of your file system, at least if you are careful. This makes it ideal for setting up new tools or testing software. Setting this up is a little beyond what I had intended to talk about so I’ll leave it to the other very good sources of info about Debian chroots on the web to explain.

Like all good Debian perl packages you can install Dancer on Debian with this simple call;

sudo apt-get install libdancer-perl

Now what?

But what happens next? Well, if all else fails, read the documentation. In this case, there is plenty. One of the great things about Perl is that there is so much good documentation that comes with it and often the same can be said for Debian. Usually when I want to learn about a particular perl module on my Debian system I do;

perldoc Foo

And in this case I did perldoc Dancer and up came the perl documentation. There are also Debian specific documents and examples in the usual Debian location; /usr/share/doc/libdancer-perl/. I didn’t even bother looking in the examples directory which is included amongst the documentation, but rather I cut and pasted the code right from ‘perldoc’. I mean, if it is as easy as the author claims, I should be up and running without issue right?

And sure enough, I was. Dancer is remarkably easy to set up. I’ll go through the remaining steps I took to test a web app on my machine. Firstly, I cut and pasted the example code in the perl documentation which is a simply hello world program;

    # webapp.pl
    #!/usr/bin/perl

    use Dancer;

    get '/' => sub {
        "Hello There!"
    };

    get '/hello/:name' => sub {
        "Hey ".params->{name}.", how are you?";
    };

    post '/new' => sub {
        "creating new entry: ".params->{name};
    };

    Dancer->dance;

Once I created the perl file called mywebapp, which contained the code above, I ran

dancer -a mywebapp

Then all you have to do is to run the resulting web app like this;

perl ./mywebapp

which will handle all of the web serving for you. This truly saves a lot of time and headache.
You can change the last “Dancer->dance” bit with the more simple “start;” if you think Dancer->dance is silly. There is also a micro blog called dancr which may be of interest. Anything more sophisticated that what I’ve show here is most likely going to be better explained by the official documentation. Point your browser to the pod on CPAN and there ought to be something helpful there.

Dancer is simple to set up and get running.

3 Responses to “Installing Dancer, a perl web framework, on Debian Wheezy”

  1. […] This post was mentioned on Twitter by Dancing Chica, perlironman. perlironman said: Jeremiah Foster: Installing Dancer, a perl web framework, on Debian Wheezy http://bit.ly/flQ39T […]

  2. […] This post is going to describe what I did to get Dancer up and running on Debian Wheezy. Dancer is a web development framework and as such aims to help you develop web applications more quickly. More here […]

  3. […] This post is going to describe what I did to get Dancer up and running on Debian Wheezy. Dancer is a web development framework and as such aims to help you develop web applications more quickly. More here […]