blib/lib/Game/Checkers/Move.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 6 / 6 totaltotal 97.4% 76 / 78 CC 6 SCAR 5.9
CC
6
Cov
98%
from_raw
3.0
is_jump
2.0
notation
2.0
CRAP 1.8
« blib/lib/Game/Checkers/Error.pm ↑ Summary bin/checkers »
1 package Game::Checkers::Move;
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 30 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use Game::Checkers::Squares;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 our $VERSION = '0.04';
10  
11 30 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 RM_FROM => 0,
13 RM_TO => 1,
14 RM_PROMOTED => 2,
15 RM_PATH => 3,
16 RM_CAPTURES => 4,
17 RM_CAPTURED => 5,
18 RM_KING => 6,
19 30 };
20  
21 has [qw/from to/] => (
22 is => 'ro',
23 isa => Int
24 30 );
25  
26 has path => (
27 is => 'ro',
28 isa => ArrayRef,
29 default => []
30 30 );
31  
32 has [qw/captures captured/] => (
33 is => 'ro',
34 isa => ArrayRef,
35 default => []
36 30 );
37  
38 has [qw/promoted king/] => (
39 is => 'ro',
40 isa => Bool,
41 default => 0
42 30 );
43  
44 has side => (
45 is => 'ro',
46 isa => Str
47 30 );
48  
49 22005 ▶sub from_raw {
Subroutine from_raw: called CC=3 SCAR=11.0
Pod documented
50 22005 my ($class, $raw, $side) = @_;
51 return $class->new(
52 from => $raw->[RM_FROM],
53 to => $raw->[RM_TO],
54 promoted => $raw->[RM_PROMOTED] ? 1 : 0,
55 22005 path => [@{$raw->[RM_PATH]}],
56 22005 captures => [@{$raw->[RM_CAPTURES]}],
57 22005 ▶ captured => [@{$raw->[RM_CAPTURED]}],
Branch: 2 branches
BranchTrueFalseTotal
$raw->[2] ? : 336 21669 22005
$raw->[6] ? : 10419 11586 22005
58 king => $raw->[RM_KING] ? 1 : 0,
59 side => $side
60 );
61 }
62  
63 87728 ▶sub to_raw {
Subroutine to_raw: called CC=1 SCAR=0.0
Pod documented
64 87728 my ($self) = @_;
65 87728 my @raw;
66 87728 $raw[RM_FROM] = $self->from;
67 87728 $raw[RM_TO] = $self->to;
68 87728 $raw[RM_PROMOTED] = $self->promoted;
69 87728 $raw[RM_PATH] = [@{$self->path}];
70 87728 $raw[RM_CAPTURES] = [@{$self->captures}];
71 87728 $raw[RM_CAPTURED] = [@{$self->captured}];
72 87728 $raw[RM_KING] = $self->king;
73 87728 return \@raw;
74 }
75  
76 20396 ▶sub is_jump {
Subroutine is_jump: called CC=2 SCAR=6.9
Pod documented
77 20396 ▶ return scalar @{$_[0]->captures} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_[0]->captures;} ? : 1617 18779 20396
78 }
79  
80 17926 ▶sub notation {
Subroutine notation: called CC=2 SCAR=6.9
Pod documented
81 17926 my ($self) = @_;
82 return $self->is_jump
83 17926 ▶ ? join 'x', @{$self->path}
Branch: 1 branch
BranchTrueFalseTotal
$self->is_jump ? : 1216 16710 17926
84 : sprintf '%d-%d', $self->from, $self->to;
85 }
86  
87 518 ▶sub coord_notation {
Subroutine coord_notation: called CC=2 SCAR=6.9
Pod documented
88 518 my ($self) = @_;
89 518 my @squares = map { Game::Checkers::Squares::coord_name($_) } @{$self->path};
90 518 ▶ return $self->is_jump
Branch: 1 branch
BranchTrueFalseTotal
$self->is_jump ? : 49 469 518
91 ? join 'x', @squares
92 : sprintf '%s-%s', $squares[0], $squares[-1];
93 }
94  
95 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
96 0 return $_[0]->notation;
97 }
98  
99 30 1;
100  
101 __END__
« blib/lib/Game/Checkers/Error.pm ↑ Summary bin/checkers »