Hi,
New to Moose here, trying to read through the docs and get a basic
grasp of this rather complex beast... As I was reading I came across
some things which bothered me and thought I would ask about them and
perhaps offer some suggestions. So here goes :)

1. In the "Moose::Manual::Attributes" documentation - at one place it says:
         "This is a dumb example"

I didn't understand why the given example is dumb. I think that's a
rather harsh word to use. Maybe a better word would be "trivial"?
Personally I thought that the given example of using a subroutine as
the default value was rather good, neither trivial nor dumb. But
probably that's just me.

2. Again in the "Moose::Manual::Attributes" documentation - in the
explanation for the default value is says:

########################################################
If you want to use a reference of any sort as the default value, you
must return it from a subroutine. This is necessary because otherwise
Perl would instantiate the reference exactly once, and it would be
shared by all objects:

 has 'mapping' => (
     is      => 'ro',
     default => {}, # wrong!
 );
Moose will throw an error if you pass a bare non-subroutine reference
as the default.

If Moose allowed this then the default mapping attribute could easily
end up shared across many objects. Instead, wrap it in a subroutine
reference:

 has 'mapping' => (
     is      => 'ro',
     default => sub { {} }, # right!
 );
This is a bit awkward, but it's just the way Perl works.
########################################################

I'm sorry but it seems as if the parts saying "This is necessary
because otherwise Perl would instantiate the reference exactly once,
and it would be shared by all objects" and "If Moose allowed this then
the default mapping attribute could easily end up shared across many
objects" are basically saying the same thing. Maybe this could be
re-worded? Maybe something like:

########################################################
If you want to use a reference of any sort as the default value, you
must return it from a subroutine. This is necessary because otherwise
Perl would instantiate the reference exactly once, and it would be
shared by all objects:

 has 'mapping' => (
     is      => 'ro',
     default => {}, # wrong!
 );

 has 'mapping' => (
     is      => 'ro',
     default => sub { {} }, # right!
 );

Moose will throw an error if you pass a bare non-subroutine reference
as the default.
########################################################

As you can see I also got rid of the last sentence - I'm sorry but to
me it just sounded too apologetic.

Frankly I think it would be better to perhaps have some code inside
Moose that if a bare non-subroutine reference is given, it is replaced
by a subroutine reference - then you could remove all of this section
:)

On a related note, reading further, I reached the "lazy" explanations.
Probably I misunderstood but wouldn't using "lazy => 1" solve the
above problem and allow people to use a bare non-subroutine reference?

3. Again in the "Moose::Manual::Attributes" documentation - in the
documentation for "trigger" it says:

   This differs from an after method modifier in two ways

However the "after method modifier" is not explained or mentioned
anywhere else in this POD. If it is explained elsewhere, maybe you
could create a link to that POD?

Regards,
--
Offer Kaye

Reply via email to