blib/lib/Game/Merrills/Move.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 18 / 18 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 13 / 13 Podpod 85.7% 6 / 7 totaltotal 98.8% 89 / 90 CC 11 SCAR 11.0
CC
11
Cov
100%
from_raw
6.0
BUILD
4.0
is_placement
2.0
CRAP 3.0
« blib/lib/Game/Merrills/Board.pm ↑ Summary blib/lib/Game/Merrills/Points.pm »
1 package Game::Merrills::Move;
2  
3 84 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 84 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 84 ▶use Object::Proto::Sugar -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 84 ▶use Game::Merrills::Points;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 84 ▶use Game::Merrills::Notation;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 84 our $VERSION = '0.02';
11  
12 84 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 84 RM_FROM => 0,
14 RM_TO => 1,
15 RM_REMOVE => 2,
16 RM_CLOSES => 3,
17 RM_FLEW => 4,
18 84 };
19  
20 has [qw/from to remove/] => (
21 is => 'ro',
22 isa => Int
23 84 );
24  
25 has closes => (
26 is => 'ro',
27 isa => Int,
28 default => 0
29 84 );
30  
31 has flew => (
32 is => 'ro',
33 isa => Bool,
34 default => 0
35 84 );
36  
37 has side => (
38 is => 'ro',
39 isa => Str
40 84 );
41  
42 1369421 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
43 1369421 my ($self) = @_;
44 1369421 ▶ die 'a move needs a point to go to' unless defined $self->to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->to 1 1369420 1369421
45 1369420 Game::Merrills::Points::_check($self->to);
46 1369419 ▶ Game::Merrills::Points::_check($self->from) if defined $self->from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->from 617442 751977 1369419
47 1369418 ▶ Game::Merrills::Points::_check($self->remove) if defined $self->remove;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->remove 210231 1159187 1369418
48 1369417 return $self;
49 }
50  
51 1369413 ▶sub from_raw {
Subroutine from_raw: called CC=6 SCAR=17.9
Pod documented
52 1369413 my ($class, $raw, $side) = @_;
53 1369413 ▶ my %part = (
Branch: 1 branch
BranchTrueFalseTotal
$raw->[4] ? : 142321 1227092 1369413
Condition100%2/2
$raw->[3] || 0
l!l
2102271159186
MC/DC100%1/1
$raw->[3] || 0
$raw->[3]
Truth table100%2/2
A
A= $raw->[3]
Aresult
11
00
54 to => $raw->[RM_TO],
55 closes => $raw->[RM_CLOSES] || 0,
56 flew => $raw->[RM_FLEW] ? 1 : 0,
57 );
58 1369413 ▶ $part{from} = $raw->[RM_FROM] if defined $raw->[RM_FROM];
Branch: 1 branch
BranchTrueFalseTotal
if defined $raw->[0] 617438 751975 1369413
59 1369413 ▶ $part{remove} = $raw->[RM_REMOVE] if defined $raw->[RM_REMOVE];
Branch: 1 branch
BranchTrueFalseTotal
if defined $raw->[2] 210227 1159186 1369413
60 1369413 ▶ $part{side} = $side if defined $side;
Branch: 1 branch
BranchTrueFalseTotal
if defined $side 1369339 74 1369413
61 1369413 return $class->new(%part);
62 }
63  
64 91956 ▶sub to_raw {
Subroutine to_raw: called CC=1 SCAR=0.0
Pod documented
65 91956 my ($self) = @_;
66 91956 my @raw;
67 91956 $raw[RM_FROM] = $self->from;
68 91956 $raw[RM_TO] = $self->to;
69 91956 $raw[RM_REMOVE] = $self->remove;
70 91956 $raw[RM_CLOSES] = $self->closes;
71 91956 $raw[RM_FLEW] = $self->flew;
72 91956 return \@raw;
73 }
74  
75 72611 ▶sub is_placement {
Subroutine is_placement: called CC=2 SCAR=6.9
Pod documented
76 72611 ▶ return defined $_[0]->from ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->from ? : 36181 36430 72611
77 }
78  
79 40915 ▶sub is_capture {
Subroutine is_capture: called CC=2 SCAR=6.9
Pod documented
80 40915 ▶ return defined $_[0]->remove ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->remove ? : 6119 34796 40915
81 }
82  
83 139291 ▶sub notation {
Subroutine notation: called CC=1 SCAR=0.0
Pod documented
84 139291 my ($self) = @_;
85 139291 return Game::Merrills::Notation::format_move({
86 from => $self->from,
87 to => $self->to,
88 remove => $self->remove,
89 });
90 }
91  
92 1 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
93 1 return $_[0]->notation;
94 }
95  
96 84 1;
97  
98 __END__
« blib/lib/Game/Merrills/Board.pm ↑ Summary blib/lib/Game/Merrills/Points.pm »