Backgammon/Turn.pm

filter: Statementstmt 73.3% 33 / 45 Branchbran 83.3% 10 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 60.0% 6 / 10 Podpod 100% 7 / 7 totaltotal 72.6% 61 / 84 CC 11 SCAR 17.0
CC
11
Cov
73%
is_doubles
12.0
notation
7.0
pips_used
6.0
CRAP 5.5
« Backgammon/Result.pm ↑ Summary Backgammon/Error.pm »
1 package Game::Backgammon::Turn;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 our $VERSION = '0.03';
9  
10 has player => (
11 is => 'ro',
12 isa => Str
13 8 );
14  
15 has [qw/dice moves/] => (
16 is => 'ro',
17 isa => ArrayRef,
18 default => []
19 8 );
20  
21 0 ▶sub is_doubles {
Subroutine is_doubles: not called CC=3 SCAR=24.8
Pod documented
22 0 my $d = $_[0]->dice;
23 0 ▶ return (@$d >= 2 && $d->[0] == $d->[1]) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@$d >= 2 && $d->[0] == $d->[1] ? : 0 0 0
Condition0%0/3
@$d >= 2 and $d->[0] == $d->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@$d >= 2 and $d->[0] == $d->[1]
@$d >= 2 $d->[0] == $d->[1]
Truth table0%0/3
A and B
A= @$d >= 2B= $d->[0] == $d->[1]
ABresult
0X0
100
111
24 }
25  
26 0 ▶sub with_move {
Subroutine with_move: not called CC=1 SCAR=6.9
Pod documented
27 0 my ($self, $move) = @_;
28 return ref($self)->new(
29 player => $self->player,
30 0 dice => [ @{ $self->dice } ],
31 0 moves => [ @{ $self->moves }, $move ]
32 );
33 }
34  
35 0 ▶sub pips_used {
Subroutine pips_used: not called CC=2 SCAR=17.9
Pod documented
36 0 my ($self) = @_;
37 0 my $n = 0;
38 0 $n += $_->die for @{ $self->moves };
39 0 return $n;
40 }
41  
42 200 ▶sub is_forfeit { return scalar @{ $_[0]->moves } ? 0 : 1 }
Subroutine is_forfeit: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_[0]->moves;} ? : 173 27 200
43  
44 920 ▶sub notation {
Subroutine notation: called CC=7 SCAR=19.5
Pod documented
45 920 my ($self) = @_;
46 920 ▶ return '(no play)' unless @{ $self->moves };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->moves;} 37 883 920
47 883 my @out;
48 883 my ($run, $count) = (undef, 0);
49 883 for my $m (@{ $self->moves }, undef) {
50 2897 ▶ if ($run && $run->same_as($m)) { $count++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($run and $run->same_as($m)) 135 2762 2897
Condition100%3/3
$run and $run->same_as($m)
!ll&&!rl&&r
8831879135
MC/DC100%2/2
$run and $run->same_as($m)
$run $run->same_as($m)
Truth table100%3/3
A and B
A= $runB= $run->same_as($m)
ABresult
0X0
100
111
51 2762 ▶ if ($run) { push @out, $run->notation . ($count > 1 ? "($count)" : '') }
Branch: 2 branches
BranchTrueFalseTotal
if ($run) 1879 883 2762
$count > 1 ? : 99 1780 1879
52 2762 ($run, $count) = ($m, 1);
53 }
54 883 return join ' ', @out;
55 }
56  
57 823556 ▶sub key {
Subroutine key: called CC=1 SCAR=0.0
Pod documented
58 823556 my ($self) = @_;
59 823556 return join ',', sort map { $_->notation } @{ $self->moves };
60 }
61  
62 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
63 0 return $_[0]->notation;
64 }
65  
66 8 1;
67  
68 __END__
« Backgammon/Result.pm ↑ Summary Backgammon/Error.pm »