3 use warnings FATAL => 'all';
5 use Test::More tests => 3;
7 # testing that we can install several different keywords into the same scope
11 use Function::Parameters;
12 use Function::Parameters {
13 action => { defaults => 'method', shift => '$monster' },
14 constructor => { defaults => 'method', shift => '$species' },
15 function => 'function',
22 action speak (@words) {
23 return join ' ', $monster->{name}, $monster->{voices}, @words;
26 action attack ($me: $you) {
27 $you->take_damage($me->{strength});
30 method take_damage ($hits) {
31 $self->{hitpoints} = calculate_damage($self->{hitpoints}, $hits);
32 if($self->{hitpoints} <= 0) {
37 function calculate_damage ($hitpoints, $damage) {
38 return $hitpoints - $damage;
43 my $hellhound = Monster->spawn( name => "Hellhound", voices => "barks", strength => 22, hitpoints => 100 );
44 is $hellhound->speak(qw(arf arf)), 'Hellhound barks arf arf';
46 my $human = Monster->spawn( name => 'human', voices => 'whispers', strength => 4, hitpoints => 16 );
47 $hellhound->attack($human);
48 is $human->{is_dead}, 1;
49 is $human->{hitpoints}, -6;