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.01';
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 1402531 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
43 1402531 my ($self) = @_;
44 1402531 ▶ die 'a move needs a point to go to' unless defined $self->to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->to 1 1402530 1402531
45 1402530 Game::Merrills::Points::_check($self->to);
46 1402529 ▶ Game::Merrills::Points::_check($self->from) if defined $self->from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->from 650857 751672 1402529
47 1402528 ▶ Game::Merrills::Points::_check($self->remove) if defined $self->remove;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->remove 212464 1190064 1402528
48 1402527 return $self;
49 }
50  
51 1402523 ▶sub from_raw {
Subroutine from_raw: called CC=6 SCAR=17.9
Pod documented
52 1402523 my ($class, $raw, $side) = @_;
53 1402523 ▶ my %part = (
Branch: 1 branch
BranchTrueFalseTotal
$raw->[4] ? : 163812 1238711 1402523
Condition100%2/2
$raw->[3] || 0
l!l
2124601190063
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 1402523 ▶ $part{from} = $raw->[RM_FROM] if defined $raw->[RM_FROM];
Branch: 1 branch
BranchTrueFalseTotal
if defined $raw->[0] 650853 751670 1402523
59 1402523 ▶ $part{remove} = $raw->[RM_REMOVE] if defined $raw->[RM_REMOVE];
Branch: 1 branch
BranchTrueFalseTotal
if defined $raw->[2] 212460 1190063 1402523
60 1402523 ▶ $part{side} = $side if defined $side;
Branch: 1 branch
BranchTrueFalseTotal
if defined $side 1402449 74 1402523
61 1402523 return $class->new(%part);
62 }
63  
64 89571 ▶sub to_raw {
Subroutine to_raw: called CC=1 SCAR=0.0
Pod documented
65 89571 my ($self) = @_;
66 89571 my @raw;
67 89571 $raw[RM_FROM] = $self->from;
68 89571 $raw[RM_TO] = $self->to;
69 89571 $raw[RM_REMOVE] = $self->remove;
70 89571 $raw[RM_CLOSES] = $self->closes;
71 89571 $raw[RM_FLEW] = $self->flew;
72 89571 return \@raw;
73 }
74  
75 73303 ▶sub is_placement {
Subroutine is_placement: called CC=2 SCAR=6.9
Pod documented
76 73303 ▶ return defined $_[0]->from ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->from ? : 36873 36430 73303
77 }
78  
79 42310 ▶sub is_capture {
Subroutine is_capture: called CC=2 SCAR=6.9
Pod documented
80 42310 ▶ return defined $_[0]->remove ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->remove ? : 6162 36148 42310
81 }
82  
83 177782 ▶sub notation {
Subroutine notation: called CC=1 SCAR=0.0
Pod documented
84 177782 my ($self) = @_;
85 177782 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 »