in reply to Re^2: Moose is lovely
in thread Moose is lovely

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

Replies are listed 'Best First'.
Re^4: Moose is lovely
by revdiablo (Prior) on Feb 29, 2008 at 20:26 UTC
    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.

      Oh, very cool. I'd missed the builder bits while reading the docs. It

      Unfortunately, it is not as well documented as it could be, we just completed a big refactoring of the type and role systems and some of the new features have not gotten documented well enough yet. The next few releases should be mostly doc updates, which should remedy this situation.

      -stvn
Re^4: Moose is lovely
by ysth (Canon) on Feb 29, 2008 at 19:32 UTC
      Does it play well with lazy?

      Yes, in fact the motivation for putting it in Class::MOP was to support the 'lazy_build' option in Moose (which is sort of documented in Moose::Meta::Attribute under "is_lazy_build", more docs to come, patches welcome and all that).

      In general if an option does not play well with another option, we consider it a "syntax" error and throw an exception at compile time.

      -stvn
      Wonderfully. There's even a shortcut for that: lazy_build => 1. It works like this:
      has foo => ( ... lazy_build => 1, ); sub _build_foo { my $self = shift; ... }
      -nuffin
      zz zZ Z Z #!perl