blib/lib/Game/Sternhalma/Result.pm

filter: Statementstmt 100% 43 / 43 Branchbran 80.0% 8 / 10 Conditioncond 52.3% 11 / 21 MC/DCmcdc 25.0% 3 / 12 Subroutinesub 100% 11 / 11 Podpod 83.3% 5 / 6 totaltotal 78.6% 81 / 103 CC 13 SCAR 15.5
CC
13
Cov
84%
BUILD
8.9
place_of
5.5
ranking
2.0
CRAP 4.7
« blib/lib/Game/Sternhalma/Engine.pm ↑ Summary blib/lib/Game/Sternhalma/Error.pm »
1 package Game::Sternhalma::Result;
2  
3 30 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use Object::Proto::Sugar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 30 our $VERSION = '0.01';
11  
12 30 my %HOW = map { $_ => 1 } qw(home cap deadlock resign);
13  
14 30 has how => (is => 'ro');
15  
16 30 has places => (is => 'ro');
17  
18 30 has ply => (is => 'ro', default => 0);
19  
20 30 has position => (is => 'ro');
21  
22 9 ▶sub BUILD {
Subroutine BUILD: called CC=8 SCAR=21.8
Pod undocumented
23 9 my ($self) = @_;
24 9 my $how = $self->how;
25 Carp::croak("Game::Sternhalma::Result: '" . (defined $how ? $how : 'undef') . "' is not a way a game ends")
26 9 ▶ unless defined $how && $HOW{$how};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $how and $HOW{$how} 1 8 9
defined $how ? : 1 0 1
Condition66%2/3
defined $how and $HOW{$how}
!ll&&!rl&&r
018
MC/DC50%1/2
defined $how and $HOW{$how}
defined $how $HOW{$how}
Truth table66%2/3
A and B
A= defined $howB= $HOW{$how}
ABresult
0X0
100
111
27 8 my $places = $self->places;
28 Carp::croak('Game::Sternhalma::Result: places is a place for every seat, 1 the best')
29 8 ▶ unless ref $places eq 'ARRAY' && @$places && !grep { !defined || !/\A[1-9][0-9]*\z/ } @$places;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $places eq "ARRAY" and @$places and not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places) 1 7 8
Condition55%5/9
ref $places eq "ARRAY" and @$places and not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
!ll&&!rl&&r
017
ref $places eq "ARRAY" and @$places
!ll&&!rl&&r
008
defined $_ && /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
0123
MC/DC33%1/3
ref $places eq "ARRAY" and @$places and not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
ref $places eq "ARRAY" @$places not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
MC/DC50%1/2
defined $_ && /\A[1-9][0-9]*\z/u
defined $_ /\A[1-9][0-9]*\z/u
Truth table50%2/4
A and B and not(C)
A= ref $places eq "ARRAY"B= @$placesC= not grep({not defined $_ && /\A[1-9][0-9]*\z/u;} @$places)
ABCresult
0XX0
10X0
1100
1111
Truth table66%2/3
A && B
A= defined $_B= /\A[1-9][0-9]*\z/u
ABresult
0X0
100
111
30 7 return;
31 }
32  
33 9 ▶sub seats { scalar @{ $_[0]->places } }
Subroutine seats: called CC=1 SCAR=0.0
Pod documented
34  
35 1 ▶sub place_of {
Subroutine place_of: called CC=4 SCAR=17.1
Pod documented
36 1 my ($self, $seat) = @_;
37 1 ▶ return undef unless defined $seat && $seat =~ /\A[0-9]+\z/ && $seat < $self->seats;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats 0 1 1
Condition33%2/6
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats
!ll&&!rl&&r
001
defined $seat and $seat =~ /\A[0-9]+\z/u
!ll&&!rl&&r
001
MC/DC0%0/3
defined $seat and $seat =~ /\A[0-9]+\z/u and $seat < $self->seats
defined $seat $seat =~ /\A[0-9]+\z/u $seat < $self->seats
Truth table25%1/4
A and B and C
A= defined $seatB= $seat =~ /\A[0-9]+\z/uC= $seat < $self->seats
ABCresult
0XX0
10X0
1100
1111
38 1 return $self->places->[$seat];
39 }
40  
41 # The seats in the order they finished, best first; seats sharing a place in
42 # seat order.
43 6 ▶sub ranking {
Subroutine ranking: called CC=2 SCAR=7.0
Pod documented
44 6 my ($self) = @_;
45 6 my $p = $self->places;
46 6 ▶ return sort { $p->[$a] <=> $p->[$b] || $a <=> $b } 0 .. $#$p;
Condition66%2/3
$p->[$a] <=> $p->[$b] || $a <=> $b
l!l&&r!l&&!r
2310
MC/DC0%0/2
$p->[$a] <=> $p->[$b] || $a <=> $b
$p->[$a] <=> $p->[$b] $a <=> $b
Truth table66%2/3
A || B
A= $p->[$a] <=> $p->[$b]B= $a <=> $b
ABresult
1X1
011
000
47 }
48  
49 # The one seat in first place, or undef when first is shared.
50 7 ▶sub winner {
Subroutine winner: called CC=2 SCAR=6.9
Pod documented
51 7 my ($self) = @_;
52 7 my @first = grep { $self->places->[$_] == 1 } 0 .. $self->seats - 1;
53 7 ▶ return @first == 1 ? $first[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@first == 1 ? : 6 1 7
54 }
55  
56 1 ▶sub ways { sort keys %HOW }
Subroutine ways: called CC=1 SCAR=0.0
Pod documented
57  
58 30 1;
59  
60 __END__
« blib/lib/Game/Sternhalma/Engine.pm ↑ Summary blib/lib/Game/Sternhalma/Error.pm »