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 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 27 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use Game::Checkers::Squares;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 27 our $VERSION = '0.03';
10  
11 27 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 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 27 };
20  
21 has [qw/from to/] => (
22 is => 'ro',
23 isa => Int
24 27 );
25  
26 has path => (
27 is => 'ro',
28 isa => ArrayRef,
29 default => []
30 27 );
31  
32 has [qw/captures captured/] => (
33 is => 'ro',
34 isa => ArrayRef,
35 default => []
36 27 );
37  
38 has [qw/promoted king/] => (
39 is => 'ro',
40 isa => Bool,
41 default => 0
42 27 );
43  
44 has side => (
45 is => 'ro',
46 isa => Str
47 27 );
48  
49 9835 ▶sub from_raw {
Subroutine from_raw: called CC=3 SCAR=11.0
Pod documented
50 9835 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 9835 path => [@{$raw->[RM_PATH]}],
56 9835 captures => [@{$raw->[RM_CAPTURES]}],
57 9835 ▶ captured => [@{$raw->[RM_CAPTURED]}],
Branch: 2 branches
BranchTrueFalseTotal
$raw->[2] ? : 143 9692 9835
$raw->[6] ? : 2692 7143 9835
58 king => $raw->[RM_KING] ? 1 : 0,
59 side => $side
60 );
61 }
62  
63 39887 ▶sub to_raw {
Subroutine to_raw: called CC=1 SCAR=0.0
Pod documented
64 39887 my ($self) = @_;
65 39887 my @raw;
66 39887 $raw[RM_FROM] = $self->from;
67 39887 $raw[RM_TO] = $self->to;
68 39887 $raw[RM_PROMOTED] = $self->promoted;
69 39887 $raw[RM_PATH] = [@{$self->path}];
70 39887 $raw[RM_CAPTURES] = [@{$self->captures}];
71 39887 $raw[RM_CAPTURED] = [@{$self->captured}];
72 39887 $raw[RM_KING] = $self->king;
73 39887 return \@raw;
74 }
75  
76 15334 ▶sub is_jump {
Subroutine is_jump: called CC=2 SCAR=6.9
Pod documented
77 15334 ▶ return scalar @{$_[0]->captures} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_[0]->captures;} ? : 1131 14203 15334
78 }
79  
80 13884 ▶sub notation {
Subroutine notation: called CC=2 SCAR=6.9
Pod documented
81 13884 my ($self) = @_;
82 return $self->is_jump
83 13884 ▶ ? join 'x', @{$self->path}
Branch: 1 branch
BranchTrueFalseTotal
$self->is_jump ? : 865 13019 13884
84 : sprintf '%d-%d', $self->from, $self->to;
85 }
86  
87 147 ▶sub coord_notation {
Subroutine coord_notation: called CC=2 SCAR=6.9
Pod documented
88 147 my ($self) = @_;
89 147 my @squares = map { Game::Checkers::Squares::coord_name($_) } @{$self->path};
90 147 ▶ return $self->is_jump
Branch: 1 branch
BranchTrueFalseTotal
$self->is_jump ? : 10 137 147
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 27 1;
100  
101 __END__
« blib/lib/Game/Checkers/Error.pm ↑ Summary bin/checkers »