|laziness, impatience, and hubris|
Moose is lovelyby revdiablo (Prior)
|on Feb 29, 2008 at 01:08 UTC||Need Help??|
I know most of you have probably heard of Moose already. Many of you have probably even used it. I am certainly not one to claim I'm the first on any given block. But, after finally bucking up and building something with it, I felt a burning itch (maybe I should get that checked out?) to share my enthusiasm.
I wrote an interface to access data from a website. I do this a lot, but the busywork involved in making even a very simple OO API usually prevents me from bothering. Mostly, I write a couple of subroutines to abstract the various WWW::Mechanize and HTML::TreeBuilder bits, build some plain data structures, and hack things up and down the stack.
On a lark, I thought I might want to do it a little differently this time. I installed Moose, went through the docs a bit, and discovered the development model was surprisingly fun. Even while learning how to prod things into the proper shape.
The beginning was crude and simple. I defined the attributes of each object with has calls, and the object interrelationships with isa declarations. The basic data model took very little time to get right. I quickly had a program that pretended it was reading my LibraryThing library.
Then I wrote default hooks that fetched the appropriate data from the site. It kind of snuck on me, but then I realized that's all I had to do. Once I had the loading code in place, it was done. I had a functional API before I even knew it. It was clear and straightforward. Even better, since the data-fetching methods were all defined with lazy turned on, the fetching doesn't happen until the data's needed.
There is a lot of functionality that comes from Moose's simple, declarative interface. All I could think of was the infamous tagline from a Ruby on Rails promotional video: look at all the things I'm not doing! I gotta say, Moose; I like it, I really do.
Three cheers for stvn!