my $person = Person.new(:life(100), :attack(1), :spell(2)); $person.weapons<a> = Weapon.new(:name<sword>, :powerLow(3), :powerHigh +(5) ); $person.weapons<s> = Weapon.new(:name<spell>, :powerLow(0), :powerHigh +(7) );
I suggest:
given my $person = Person.new(...) { given .weapons { .<a> = Weapon.new(...); .<b> = Weapon.new(...); } }
Or simply:
given my $person = Person.new(...) { .weapons = { a => Weapon.new(...), b => Weapon.new(...) }; }
Or maybe just
my $person = Person.new( ..., weapons => { a => Weapon.new(...), b => Weapon.new(...) } };
I personally think :pair() style should not be used for setting anything that's clearly key and value in a hash or object. :foo() is very nice for things that alter behaviour:
my $socket = Socket.new( localport => 80, localaddr => '127.0.0.1', :proto<tcp> :listen(5) :timeout(500) :reuse ); my @users = slurp '/etc/passwd' :chomp; my @even = 2..10 :by(2);

All code is untested.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


In reply to Re: P6: OO Wizard Game (RPG kinda, sorta) by Juerd
in thread P6: OO Wizard Game (RPG kinda, sorta) by eric256

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.