yui iconperl icon

Comparing CPAN Modules with YUI DataTable

Posted in , Fri, 09 Nov 2007 06:09:00 GMT

There is a lot of choice on the CPAN for open source Perl libraries and sometimes it's difficult to get an idea of how modules compare to each other. CPAN Ratings is a good source of reviews but it's not convenient to compare one module with another. To provide a partial solution, I whipped up a quick CPAN Compare page which will pull the CPAN Ratings from a number of modules and summarize them for you.

CPAN Compare Modules

I decided to use YUI DataTable for this. I've heard good things about YUI so I decided to give it a try. Getting the example code to work off of the Yahoo website almost as straight forward as say using Scriptaculous demos but it was faster than working with Dojo in the early days. The nice thing about the DataTable is that it takes a JavaScript array which can be populated using server-side JSON generated code. I used JSON::XS for this.

YUI DataTable has a nice sorting feature and it can sort on text, numbers, dates, etc. However, it does not seem to be able to sort on visual information only so if you include HTML markup, that will be used for sorting as well. To get around this I used standard text sorting and customized the title fields to assist in the sorting. For example, in a link, I start with <a title=" instead of <a href=" because title is arbitrary and can be used to mirror the InnerHTML. For numbers a text sort will have 25 come before 4 so I added leading zeros to numbers using sprintf and put them in the title attribute as well.

A few Perl modules and the Logo Creator website made this easy to set up. YUI DataTable has a nice default CSS so I just left that as is.

Note: YUI DataTable is convenient if you just drop in a Perl data structure and have it generate the HTML and JS for you. This script uses 3 DataTables (ratings, popular and recent) so I wrote a Perl wrapper for YUI which takes a hashref and generates the client code, extracting the fields from the column definitions. This works because YUI does not require the HTML table to be built beforehand. By not having an underlying table, it's faster to get running but also won't fallback as nicely for people who aren't running JS (8% of users?). As an alternative, jQuery has a couple of add ons which work by enhancing an existing HTML table. jQuery has some nice syntax but I haven't gotten around to using it yet. Perhaps it's worth a look.

del.icio.us:Comparing CPAN Modules with YUI DataTable digg:Comparing CPAN Modules with YUI DataTable reddit:Comparing CPAN Modules with YUI DataTable spurl:Comparing CPAN Modules with YUI DataTable wists:Comparing CPAN Modules with YUI DataTable simpy:Comparing CPAN Modules with YUI DataTable newsvine:Comparing CPAN Modules with YUI DataTable blinklist:Comparing CPAN Modules with YUI DataTable furl:Comparing CPAN Modules with YUI DataTable fark:Comparing CPAN Modules with YUI DataTable blogmarks:Comparing CPAN Modules with YUI DataTable Y!:Comparing CPAN Modules with YUI DataTable smarking:Comparing CPAN Modules with YUI DataTable magnolia:Comparing CPAN Modules with YUI DataTable segnalo:Comparing CPAN Modules with YUI DataTable

4 comments

Comments

  1. Ask Bjørn Hansen said 23 days later:

    Any plans to make this work (again?)?

    :-)

    (the buttons just shows some blog posting from your blog)

    - ask
  2. John Wang said about 1 month later:

    Thanks for the heads up. It’s working again :)

  3. Just in said 4 months later:

    Would like to see the entire source code :)

  4. John Wang said 7 months later:

    The most useful part of the source code is probably the Perl YUI wrapper I wrote to take away some of the pain of writing the JS. You can find it here.

    There are two schools of thought on writing server-side wrappers for AJAX/DHTML libraries with one side thinking they are the bomb (Rails folks) and others thinking that writing in one language for server-side code and JS for the client-side is the way to go (Catalyst folks), for YUI DataTable, I thought it was definitely nice to have a Perl wrapper.

(leave url/email »)

   Comment Markup Help Preview comment