develooper Front page | perl.moose | Postings from July 2014

Modifying composed attribute characteristics

Thread Next
Diab Jerius
July 22, 2014 21:17
Modifying composed attribute characteristics
Message ID:
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?



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About