blib/lib/Acme/CoC/Dice.pm

filter: Statementstmt 100% 32 / 32 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 89.8% 44 / 49 CC 6 SCAR 13.3
CC
6
Cov
92%
role
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
↑ Summary Build »
1 package Acme::CoC::Dice;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.02';
10  
11 sub role {
12 4 ▶ my ($self, $command) = @_;
Subroutine role: called CC=6 SCAR=18.0
Pod documented
13  
14 # MdN in $command can be separated to M/d/N, and M is the times of roling dice, N is the number of sided dice.
15 4 ▶ return $self->role_skill if $command =~ /^skill$/;
Branch: 1 branch
BranchTrueFalseTotal
if $command =~ /^skill$/ 1 3 4
16  
17 3 $command =~ /([1-9][0-9]*)d([1-9][0-9]*)/;
18 3 my $role_result = {
19 message => 'input invalid command',
20 };
21 3 ▶ return $role_result unless $command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command 0 3 3
22  
23 3 ▶ my $times = $1 || 1;
Condition50%1/2
$1 || 1
l!l
30
MC/DC0%0/1
$1 || 1
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
24 3 ▶ my $sided_dice = $2 || 100;
Condition50%1/2
$2 || 100
l!l
30
MC/DC0%0/1
$2 || 100
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
25 3 my $results = [];
26 3 my $sum = 0;
27  
28 3 for (1..$times) {
29 12 my $rand_num = int(rand($sided_dice)) + 1;
30 12 push @{ $results }, $rand_num;
31 12 $sum += $rand_num;
32 }
33  
34 $role_result = {
35 3 dices => $results,
36 sum => $sum,
37 };
38 3 return $role_result;
39 }
40  
41 sub role_skill {
42 1 ▶ my ($self) = @_;
Subroutine role_skill: called CC=1 SCAR=0.0
43  
44 1 return $self->role('1d100');
45 }
46  
47 2 1;
48 __END__
↑ Summary Build »