Subject: | Doesn't support roles in any kind of useful way |
use v5.12;
use strict;
use warnings;
package Paper { use Moose; }
package Scissors { use Moose; }
package Rock { use Moose; }
package Lizard { use Moose; }
package Spock { use Moose; }
package Game::Role::BaseCase {
use Moose::Role;
use MooseX::MultiMethods;
multi method play (Any $x, Any $y) { 0 }
}
package Game::Role::StandardCombos {
use Moose::Role;
use MooseX::MultiMethods;
multi method play (Paper $x, Rock $y) { 1 }
multi method play (Scissors $x, Paper $y) { 1 }
multi method play (Rock $x, Scissors $y) { 1 }
}
package Game::Role::ExtraCombos {
use Moose::Role;
use MooseX::MultiMethods;
multi method play (Paper $x, Spock $y) { 1 }
multi method play (Scissors $x, Lizard $y) { 1 }
multi method play (Rock $x, Lizard $y) { 1 }
multi method play (Lizard $x, Paper $y) { 1 }
multi method play (Lizard $x, Spock $y) { 1 }
multi method play (Spock $x, Rock $y) { 1 }
multi method play (Spock $x, Scissors $y) { 1 }
}
package Game {
use Moose;
use MooseX::MultiMethods;
with qw(
Game::Role::BaseCase
Game::Role::StandardCombos
Game::Role::ExtraCombos
);
}
# Expected (or at least hoped!) outcome...
my $game = Game->new;
say $game->play(Paper->new, Rock->new); # 1, Paper covers Rock
say $game->play(Spock->new, Paper->new); # 0, Paper disproves Spock
say $game->play(Spock->new, Scissors->new); # 1, Spock smashes Scissors