in reply to P6: OO Wizard Game (RPG kinda, sorta)
I suggest: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) );
Or simply:given my $person = Person.new(...) { given .weapons { .<a> = Weapon.new(...); .<b> = Weapon.new(...); } }
Or maybe justgiven 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 $person = Person.new( ..., weapons => { a => Weapon.new(...), b => Weapon.new(...) } };
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' }
|
|---|