Can the Boo constant consume a role? I don't think so.
I know that your replies are usually both knowledgeable and helpful, as I've learned much from many of them, so I'll skip over the 'angst' remark and try to provide an example that better conveys my aim:
package Ghost { use Moo; with('Attacker'); has 'Str' => ( is => 'ro', default => sub { '8' } ); has 'Dex' => ( is => 'ro', default => sub { '16' } ); has 'Con' => ( is => 'ro', default => sub { '10' } ); has 'Int' => ( is => 'ro', default => sub { '10' } ); has 'Wis' => ( is => 'ro', default => sub { '10' } ); has 'Cha' => ( is => 'ro', default => sub { '6' } ); } my $boo = Ghost->new( Int => '14', Con => '16' );
I'm asking about a way to state that all the attributes of Ghost are readonly, as I think that:
package Ghost { use Moo; use Moo::AllAttributesAreReadonly; with('Attacker'); has 'Str' => ( default => sub { '8' } ); has 'Dex' => ( default => sub { '16' } ); has 'Con' => ( default => sub { '10' } ); has 'Int' => ( default => sub { '10' } ); has 'Wis' => ( default => sub { '10' } ); has 'Cha' => ( default => sub { '6' } ); } my $boo = Ghost->new( Int => '14', Con => '16' );
or something like this, would be much more elegant than the way I am using now. If my "classes" did not consume roles, had no methods, and were as simple as the one I provided, then I would have no reason to use Moo in the first place.
- Luke
In reply to Re^4: Making 'all' the attributes read only by default (Moo)
by blindluke
in thread Making 'all' the attributes read only by default (Moo)
by blindluke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |