Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Modifying composed attribute characteristics

4 views
Skip to first unread message

Diab Jerius

unread,
Jul 22, 2014, 5:16:27 PM7/22/14
to mo...@perl.org
I'm using Moo and would like to override a default value for a
composed attribute after composing the role.

This works (with Moose as well):

use Moo;

package R {
use Moo::Role;
has a => ( is => 'ro', default => 2 );
}


package P {
use Moo;
with 'R';
has '+a' => ( default => 3 );
}


say P->new->a;


AFAIK, the Moo (and Moose) documentation only mentions this syntax
when extending classes, not when composing roles.

Is this behavior simply a side effect of implementation, or is it
considered defined behavior?


Thanks,

Diab

Chris Marshall

unread,
Jul 24, 2014, 1:35:40 PM7/24/14
to Diab Jerius, mo...@perl.org
The Moose 2.1201 pod seems to say it is defined behavior:

has +$name => %options
This is variation on the normal attribute creator "has" which
allows you to clone and extend an attribute from a superclass or
from a role. Here is an example of the superclass usage: ...

Given that Moo is supposed to be Moose-compatible, the same
seems likely true for Moo.

--Chris

Diab Jerius

unread,
Jul 30, 2014, 10:58:38 AM7/30/14
to Chris Marshall, mo...@perl.org
Chris,

Thanks; I'd looked through Moose::Manual (in particular
Moose::Manual::Attributes) and missed that documentation in Moose.pm
itself.

Diab
0 new messages