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:

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"
In some ways builder can be seen as being equivalent to:
has 'foo' => (is => 'rw', default => sub { $_[0]->build_foo });
although the actual implementation is different (mostly for performance reasons).

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:

I will say that it is rare that you need to use the metaclasses in Moose and they should always be used sparingly. It is a powerful tool and one that is really easy to abuse, not unlike Perl itself actually.

-stvn

In reply to Re: Moose - nalia by stvn
in thread Moose - nalia by doc_faustroll

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.