blib/lib/Bot/Cobalt/Plugin/Games/RockPaperScissors.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 43 CC 5 SCAR 28.7
CC
5
Cov
0%
execute
30.0
new
2.0
BEGIN
2.0
CRAP 17.6
1 package Bot::Cobalt::Plugin::Games::RockPaperScissors;
2 $Bot::Cobalt::Plugin::Games::RockPaperScissors::VERSION = '0.021003';
3 use v5.10;
4 use strict; use warnings;
5  
6 sub new { bless [], shift }
7  
8 sub execute {
9 my ($self, $msg, $rps) = @_;
10 my $nick = $msg->src_nick // '';
11 $rps = lc($rps // '');
12  
13 state $beats = +{
14 scissors => 'paper',
15 paper => 'rock',
16 rock => 'scissors',
17 };
18  
19 if (! $rps) {
20 return "What did you want to throw, ${nick}?"
21 } elsif (! exists $beats->{$rps}) {
22 return "${nick}: You gotta throw rock, paper, or scissors!"
23 }
24  
25 my $throw = (keys %$beats)[rand(keys %$beats)];
26  
27 $throw eq $rps ? "$nick threw $rps, I threw $throw -- it's a tie!"
28 : $beats->{$throw} eq $rps ? "$nick threw $rps, I threw $throw -- I win!"
29 : "$nick threw $rps, I threw $throw -- you win :("
30 }
31  
32 1;
33 __END__