First, thanks for the compliments, and sorry about the docs. We are well aware of the deficiencies in the docs and actually Moose is currently under a feature freeze until the docs are brought up to date. We had a mad rush of features and improvements in the last few months, but (as will always happen) the docs kind of lagged behind. The next few releases will probably be entirely doc updates (and bug fixes of course). In the meantime, there are a number of articles and presentations linked to on the Moose site that might help fill in some holes (also note the recently uploaded podcast from the recent PDX.pm meeting).
The builder option is somewhat similar, although it is passed as a scalar method name and not a coderef. Why a builder and a trigger option, and what are the finer points of the builder option?
The 'builder' option is actually is actually documented in Class::MOP::Attribute, one of the things we are going to do is to move some of those docs up to Moose for easier access.
The 'builder' option is actually closer to the 'default' option then it is 'trigger'. A 'builder' is used to initialize an instance's slot. The reason it is only a string is that it is meant to be a method name and therefore to be easily overrideable in a subclass. Here is an example:
In some ways builder can be seen as being equivalent to:package Foo; use Moose; has 'bar' => (is => 'rw', builder => 'build_bar'); sub build_bar { 'Foo::bar' } package Foo::Bar; use Moose; extends 'Foo'; sub build_bar { 'Foo::Bar::bar' } print Foo->new->bar # "Foo::bar" print Foo::Bar->new->bar; # "Foo::Bar::bar"
although the actual implementation is different (mostly for performance reasons).has 'foo' => (is => 'rw', default => sub { $_[0]->build_foo });
Now for a more fun question. Metaclasses have been described as a solution in search of a problem. Anyone care to share any clever problems and solutions using Metaclasses in Moose?
Actually, Moose itself would not be possible without the metaclasses provided by Class::MOP. That is justification enough for metaclasses for me :)
Also, Moose can be extended using metaclasses, some examples of that include:
In reply to Re: Moose - nalia
by stvn
in thread Moose - nalia
by doc_faustroll
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |