HTML::TagCloud::Sortable

LTjake on 2007-10-03T20:09:02

HTML tag clouds are pretty popular in a lot of websites. For the project I'm working on right now, i decided to try and mimic del.icio.us's implementation which is sortable by name or by frequency.

HTML::TagCloud is definitely the defacto standard for generating tag clouds in perl. I sorted the data in my SQL query based on the parameter pulled in from the query string and stuffed the data into the cloud. However, no matter what I did the output was always alphabetical.

It turns out that HTML::TagCloud doesn't retain insertion order and automatically sorts your data by tag name.

With Leon's blessing, HTML::TagCloud::Sortable is born. It's API compatible with HTML::TagCloud -- it even passes the same test suite. However, this subclass will also retain the insertion order, allow you to store arbitrary data for tags and sort of any tag field.

It's a little ironic that my main use case for the module was to not sort the tags, but, oh well.