Slashdot Mirror


Lighter Side of CPAN

bleechack writes: "Looks like Perl.com is fully ready for the release of Lord of the Rings with this week's "Lighter Side of CPAN"."

1 of 66 comments (clear)

  1. Good Parts Version (TM) by PeterClark · · Score: 0, Redundant

    It's way to late, and I should be in bed, but I thought I would c/p the relevant parts of the article for those at work tomorrow who find the site /.ed. Sorry that I didn't preserve the HTML formatting. The rest is amusing, too, so you might want to come back to it once the servers have recovered. (If you're the type of person who gets excited over perl modules, that is. The rest of you might just want to watch CSPAN. :)
    :Peter
    ---
    Moving swiftly on, we come to Date::Tolkien::Shire, a king amongst date modules. Most newspapers carry an ``on this day in history'' column -- where you find, for instance, that you were born on the same day as the man who invented chili-paste -- but no broadsheet will tell you what happened to Frodo and his valiant companions as they fought to free Middle Earth from the scourge of the Dark Lord. The undeceptively simple:

    use Date::Tolkien::Shire;
    print Date::Tolkien::Shire->new(time)->on_date, "\n";

    outputs (well, output a few days ago):

    Highday Winterfilth 30 7465
    The four Hobbits arrive at the Brandywine Bridge in the dark, 1419.

    What better task could there be for crontab but to run this in the wee hours and update /etc/motd for our later enjoyment. Implementing this is, as ever, left as an exercise for the interested reader.

    There is a more useful side to Date::Tolkien::Shire or, at the very least, it does light the way for other modules. As well as the on_date() method it provides an overloaded interface to the dates it returns. This allows you to compare dates and times as if they were normal numbers, so that:

    $date1 = Date::Tolkien::Shire->new(time);
    $date2 = Date::tolkien::Shire->new(time - 1e6);

    print 'time is '.( $date1 > $date2 ? 'later':'earlier' ).
    "than time -1e6\n";

    prints time is later than time -1e6, the more prosaic Date::Simple module provides a similar interface for real dates and ensures they stringify with ISO formatting.