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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.