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

Modifying composed attribute characteristics

Thread Next
From:
Diab Jerius
Date:
July 22, 2014 21:17
Subject:
Modifying composed attribute characteristics
Message ID:
CADpyd5B0VL2XEk5ELSc15Ov5KpjxAt+_GUTLE2A=4pW9017RcA@mail.gmail.com
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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About