Anyway been meaning to get into Moose for ages now and so far only used it to subclass an old library I had.
So as a good way of getting me feet dirty I went ahead and done the above Doodle stuff in Moose….

I’m not sure if the Doodle example is a bit contrived but I decided to replicate how the objects worked in exactly same way. However I slightly amended the contructor because it was i) simpler to do this way in Perl! & ii) Probably more accurate as an interface spec!! (changes are… locations & events are clearly defined as a list of things).

And there we go. The Moose example produced twice as many lines! However this isn’t the fault of Moose but mainly because I had to manually format stuff due to issues with the WordPress syntax highlighter with the Perl code ;-(

Yes the “Collector” feature in Doodle does look interesting and so the coerce on ‘Places’ required extra lines in this Moose example to mimic it. And I totally agree with u about the coercions & code size… it shouldn’t be changed because they’re beautifully declarative.

When I get around to “Part 2” (yeah… dream on!) I was hoping to mention that they might be a “Collector” equivalent in Moose but u’ve now answered that question ;-( Still perhaps a MooseX Collector module is around the corner from one of us!

/I3az/

PS. I did first look at Moose back in 2006. However at the time I had just initiated a style guide policy using PBP for all our code and so was using Class::Std everywhere. Anyway got some big projects with a new startup and I plan to use Moose from now on in.

You should come by #moose on irc.perl.org and discuss a MooseX:: collector module of some kind. There were several other people interested in a more automagic coercion solution, and the collector idea would fit in right nicely with this I think.

“String eval as metaprogramming” – problem with Ruby in this regard is that you run into the “You must use string eval” wall surprisingly quickly. There’s always people who’ll tell you that you should use string eval because it’s faster, but they’re just idiots. Some of the stuff in Ruby 1.9 means that Ruby metaprogrammers will hit that wall a good deal later, but it’s still problematic.

Just want to to say I really enjoyed your MooseX::Declare presentation at the London Perl Mongers tech talk last night.

Unfortunately didn’t get chance to introduce myself because had to leave straight after the event. By the sounds of your rekindled joy for using MooSex… sorry Perl 😉 …. then we may still bump into each other at some point in the near future.

Most rubyists do subscribe to the notion that ‘eval is evil’ but as Piers points out there are some limitations in ruby 1.8.6 that sometimes force you to use it.

doodle uses string eval only to get around a limitation of ruby 1.8.6’s define_method which does not allow blocks as arguments. Otherwise, there’s nothing in the collector code that couldn’t be done cleanly (though the current implementation pragmatically takes advantage of the fact that the line has already been crossed). The upcoming revision of doodle for ruby 1.8.7 and 1.9.1 will not have to use any string evals.

About…..

My name is Barry Walsh. I'm a freelance IT consultant from London, UK. [more]

This blog is mostly about Perl programming because this is what I use and love (and occasionally hate!) for the majority of my working (and sometimes non-working) day.

Occasionally I will touch on other subjects like PostgreSQL, Mac OSX, UNIX, Linux, Ruby, jQuery, Javascript, XML and many more techie things that I also play with regularly. Other non techie aspects of my life may slip in now and again but I'll try and keep that to a minimum because its normally boring anyway :)