Monthly Archives: August 2010

Net::Songkick

Sometimes it’s good to just take a new idea and hack on it for a couple of hours to see what happens. That’s what I’ve done this evening.

I’ve been using Songkick for a while. Songkick is a web site that tracks users’ attendance at gigs. I’ve been tracking the gigs I’ve been going to as well as trying to fill in over thirty years of old gigs.

I’ve known for some time that Songkick has an API, but until yesterday the API has been for invited partners only. But yesterday on Get Satisfaction they announced that it was now public.

The public API doesn’t do that much yet. There are only four documented calls. But it’s already useful and I’m sure it will gain more functionality quickly.

And this evening I’ve spent some time writing a very simple Net::Songkick module. This is really just a proof of concept, but I’ve got big plans for improving it. And I can already write a useful program like this:

#!/usr/bin/perl

use strict;
use warnings;

use XML::LibXML;
use Net::Songkick;

my $user = shift || 'davorg';

my $sk = Net::Songkick->new({
  api_key => $ENV{SONGKICK_API_KEY}
});

my $xml = $sk->get_upcoming_events({
  user => $user,
});

my $xp = XML::LibXML->new->parse_string($xml);
foreach ($xp->findnodes('//event/@displayName')) {
  print $_->to_literal, "\n";
}

If you have any interest in gigs then I highly recommend Songkick to you. And if you like attending gigs and hacking Perl (although not necessarily at the same time) then why not give Net::Songkick a try. All you’ll need is an API key from Songkick.

There’s a Github repository too; if you feel like hacking on it…

Learning About Traits

I’ve been teaching basic Moose in my training courses for several years now. And, as I’ve mentioned before, I’ve been slowly converting some of my CPAN modules to use Moose. But there are still bits of Moose that I haven’t really needed to get to grips with.

One such area is Moose’s support for Traits. Oh, I knew vaguely what they were and I understood why you might use them. But I’d never implemented a system using traits, so my knowledge about how you’d actually use them was a bit shaky to say the least.

But over the last few days I’ve learned quite a lot about how to use traits. And I’ve had to learn it pretty quickly.

It all started a few weeks ago when I got a github pull request fromĀ Oliver Charles. Oliver had taken a fork of my Perlanet repository and had massively refactored the codebase so that all the clever bits were implemented as traits.

What this means is that the core Perlanet code is pretty dumb. In order to do anything really useful with it to need to add in some traits. There are traits to read the configuration from a YAML file, traits to carry out various kinds of cleaning of the input and a trait to produce the output using the Template Toolkit. There are also traits to handle caching and OPML generation. All in all it makes the code far nicer to work on.

Oh, and there’s a Perlanet::Simple module which uses all of the traits required to implement the Perlanet behaviour that users currently expect.

There were a few problems with Oliver’s initial version. Some of the dependencies weren’t quite right. But we soon fixed that and last week I finally released Perlanet 0.47 which implemented these changes.

Then I installed it on the server which hosts most of my planets. And everything broke.

So I’ve spent a lot of the weekend fixing these issues. Part of it was that Oliver’s changes assumed some configuration file changes that I hadn’t implemented. I changed his changes so that they worked with the existing configuration settings (we don’t want users having to change configuration files unnecessarily). Other changes were harder to track down. I particularly enjoyed one where no feeds were fetched unless the user turned on OPML support. I learned a lot about how traits worked by tracking that one down.

But it all seems to be fixed now. Perlanet version 0.51 is available on CPAN and it will hopefully be a lot easier to customise to your needs. I hope we’ll see a number of other Perlanet traits appearing over the next few months.

And, most importantly, I’ve learnt a lot about traits. I think I understand them now.

If you want to learn traits, I can highly recommend asking someone to implement traits in one of your projects. And it’s even better if they do it in a slightly broken way so that you need to debug it.