An Unknown Indian

Thoughts of a FOSS enthusiast

Dancer – Dance with Perl

Posted by Balachandran on January 21, 2013

Some of those who know me might be really surprised to see a post on Perl in my blog. Well, the fact is that I use Perl at office as of now, and so I know some basics(of Perl).

A couple of weeks back, I started working on this task of creating a tracker application for the Patches/Hotfixes that our team releases. This tracker app would have the list of bugs being fixed, the QA engineer testing them, and the current status of the release/HF.

It was suggested that I use Perl since everyone else in the team is a full-time Perl programmer. And so started the journey.

I am not new to web programming. I, with my friends, have done everything from raw PHP-everywhere to decent apps with Django(python). Though I am very bad with the UI, web programming(including templates) is something that I have done repeatedly, whether I like or not. This time, since the language was Perl, it was something new.

So, I decided to take a look at the frameworks that are available for use. There was Catalyst that a lot of people suggested. To me, it looked scary. And then, I hit upon Dancer. For those of you who have use Flask, this is the Perl version of it. This is a micro-framework, which works with Template::Toolkit and has a lot of plugins(For eg. the Database or the Upload plugins). The configuration is through a yaml(config.yml), and that’s  where you say what type of database, the DB credentials etc, the template engine to use etc. and all other configuration. The code layout has a lib folder into which the app’s perl modules will go and a views folder into which the templates go. It has a public folder that has the static content – images, css, js and a environments folder which holds a bunch of yaml files for each env – Dev, Production etc. The actual app is a script named app.pl located in the bin folder. I will  create a separate “HowTo” blog post. But here is the basic idea.

You create a bunch of coderefs that process the requests. Your application can across a bunch of Perl modules, that get called from these code ref. A typical coderef would be

<HTTP VERB> '<ROUTE>' => sub {

};

A simple code would look like.

get '/home/' => sub {
    my $name = "Bala";
    template 'home.tt' , {
        'username' => $name.
    };
};
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: