A Perl Module Advent Calendar: About

This goes along way to proving what I always say: I come up with the best ideas when I'm hung over.

Last time it was after our media office party. I wrote a script that allowed you to add speech bubbles onto the photos of the party from night before on the web (using Perl and GD.) Oh, how I laughed when my machine got up to a load of 38 (Good old Linux though, it didn't fall over.) Which just goes to show you need to think hard about these things before you release them. You'd have thought I'd have learned my lesson by now.

Anyway, the reason why I was getting drunk was a meeting of london.pm. Perl mongers. What fun. That's another time when we come up with crazy ideas.

As a new years resolution last year I gave up eating chocolate. So this year I couldn't have one of those nice advent calendars that gives you a chocolate based sweet each morning. So in my lunch break I wrote this module. It's not my best code, (infact it's pretty close to my worst code ever) but it was quick and dirty and got the job done. Hey, did I mention I was hungover?

Enough of this, It's friday night, and I'm going down the pub.

Mark Fowler <mark@twoshortplanks.com>
Technology Developer, Profero

How I did this

The basics for the code were written in the Template Toolkit, my templating system of choice. It's really just two pages. Oh, and maybe some other scripts I'd already written.

All code copyright Mark Fowler 2000. This code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The main front page. This is a psudo html page that simply has to decide what to provide links to (which days are currently valid.) Look, I even used the Template::Plugin::Table plugin.
An even more simple page that just displays the correct thing for the day, making sure that someone isn't peeking. All times are in GMT, as that's what time zone both me and the server are in.
A very simple plugin that simply returns the current day of month and works out the suffix of the day. I could have written this directly in template toolkit, but I was trying to keep the logic out of the html code. Always a good thing.
The module that displays the correct content for the day. Not shown here because then you could peek ahead.
A script that basically converts whatever psudo html pages are passed to it through template toolkit into a real page. This avoids using mod_perl. If I knew this many people were going to look at it, I'd have written it in mod_perl. Did I mention that I was hungover?
404.cgi, Url2Image.pm
A script and module that allow you to dynamically create textual images (like the 1st, 2nd etc buttons) if they're not found on the server from the text in the url itself, a .fontrc file, a true type font, and a background image. We've all read that article right? Well this is my implementation. Oh, and it's really bad. Bit of a rush job ;-)

See Also

The modern FAQ.