in reply to Moose is lovely

Is this code you can show us?

Replies are listed 'Best First'.
Re^2: Moose is lovely
by revdiablo (Prior) on Feb 29, 2008 at 06:42 UTC

    Sure! I've omitted the _fetch routines here, because they're not particularly relevant to the Moose portions of the code, and the size would be a bit unmanageable.

      Very nice, I am glad you are enjoying Moose :)

      Just one suggestion, if your "default" subs get large, it is usualy a good idea to convert them to 'builder' methods instead. You can find this feature documented in Class::MOP::Attribute. This:

      has 'foo' => ( builder => 'build_foo' );
      is basically a shortcut for:
      has 'foo' => ( default => sub { (shift)->build_foo } );
      It also gives the added benefit that any subclasses can easily override 'build_foo' themselves to get additional behavior.

      -stvn
        Just one suggestion, if your "default" subs get large, it is usualy a good idea to convert them to 'builder' methods instead.

        Oh, very cool. I'd missed the builder bits while reading the docs. It does seem like a nice shortcut, and I kind of like the additional semantic alignment. I'm actually building the value, not setting a default value. Granted, it doesn't make a practical difference. But when there're two ways to do something, and one of them is a better semantic match, I usually choose that one.

      You are my new hero.

      I was at the to.pm meeting last night and I asked "has anyone used Moose?" The answer was no but talexb suggest I post to perlmonks to see if anyone knew of some real-world examples on CPAN. So here I am and here this is ready and waiting for me!

      I admit, I don't quite grok it despite looking at merlyn's articles on the subject. But something keeps telling me "this is good stuff, you should learn it".

      Methinks you are a little psychic. My thanks.

      --
      meraxes

      -- A Møøse once bit my sister