blib/lib/Game/RoyalUr/Notation.pm

filter: Statementstmt 90.4% 190 / 210 Branchbran 56.6% 94 / 166 Conditioncond 37.9% 30 / 79 MC/DCmcdc 17.3% 8 / 46 Subroutinesub 100% 24 / 24 Podpod 100% 8 / 8 totaltotal 66.4% 354 / 533 CC 114 SCAR 38.8
CC
114
Cov
69%
__ANON__
82.9
validate_position
81.5
parse_record
72.5
CRAP 48.5
↑ Summary blib/lib/Game/RoyalUr/Dice.pm »
1 package Game::RoyalUr::Notation;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Game::RoyalUr::Dice ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '0.03';
13  
14 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 POS_OK => 0,
16 POS_NULL => 1,
17 POS_ROWS => 2,
18 POS_WIDTH => 3,
19 POS_LETTER => 4,
20 POS_GAP => 5,
21 POS_X => 6,
22 POS_SIDE => 7,
23 POS_COUNT => 8,
24 POS_FIELD => 9,
25 POS_LONG => 10,
26 3 };
27  
28 3 our (@EXPORT_OK, %EXPORT_TAGS);
29 3 my (%MISSING, %ROSETTE, %NAMED, @FIELDS, %SIDE_OF, %LETTER_OF, %RESULT_OK);
30 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 @EXPORT_OK = qw(
32 square_ok parse_move format_move format_display format_forfeit
33 validate_position parse_record format_record
34 POS_OK POS_NULL POS_ROWS POS_WIDTH POS_LETTER POS_GAP POS_X
35 POS_SIDE POS_COUNT POS_FIELD POS_LONG
36 );
37 3 %EXPORT_TAGS = (all => \@EXPORT_OK);
38  
39 3 %MISSING = map { $_ => 1 } qw(e1 f1 e3 f3);
40 3 %ROSETTE = map { $_ => 1 } qw(a1 g1 a3 g3 d2);
41 3 %NAMED = (
42 finkel => { route => 'short', dice => 4, zero_rolls => 0, safe_rosettes => 1, pieces => 7 },
43 masters => { route => 'long', dice => 3, zero_rolls => 4, safe_rosettes => 0, pieces => 7 },
44 );
45 3 @FIELDS = qw(route dice zero_rolls safe_rosettes pieces);
46 3 %SIDE_OF = (l => 'light', d => 'dark');
47 3 %LETTER_OF = (light => 'l', dark => 'd');
48 3 %RESULT_OK = (
49 'light home' => 1, 'dark home' => 1,
50 'light resign' => 1, 'dark resign' => 1,
51 'draw ply_cap' => 1,
52 );
53 }
54  
55 6 ▶sub square_ok {
Subroutine square_ok: called CC=4 SCAR=14.9
Pod documented
56 6 my ($name) = @_;
57 6 ▶ return 0 unless defined $name && $name =~ /\A[a-h][1-3]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name =~ /\A[a-h][1-3]\z/ 0 6 6
Condition33%1/3
defined $name and $name =~ /\A[a-h][1-3]\z/
!ll&&!rl&&r
006
MC/DC0%0/2
defined $name and $name =~ /\A[a-h][1-3]\z/
defined $name $name =~ /\A[a-h][1-3]\z/
Truth table33%1/3
A and B
A= defined $nameB= $name =~ /\A[a-h][1-3]\z/
ABresult
0X0
100
111
58 6 ▶ return $MISSING{$name} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$MISSING{$name} ? : 1 5 6
59 }
60  
61 10 ▶my $place = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
62 10 my ($text) = @_;
63 10 my $lower = lc $text;
64 10 ▶ return $lower if $lower eq 'hand' || $lower eq 'home';
Branch: 1 branch
BranchTrueFalseTotal
if $lower eq "hand" or $lower eq "home" 4 6 10
Condition66%2/3
$lower eq "hand" or $lower eq "home"
l!l&&r!l&&!r
406
MC/DC50%1/2
$lower eq "hand" or $lower eq "home"
$lower eq "hand" $lower eq "home"
Truth table66%2/3
A or B
A= $lower eq "hand"B= $lower eq "home"
ABresult
1X1
011
000
65 6 ▶ return undef unless $text =~ /\A[A-Ha-h][1-3]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\A[A-Ha-h][1-3]\z/ 0 6 6
66 6 ▶ return square_ok($lower) ? $lower : undef;
Branch: 1 branch
BranchTrueFalseTotal
square_ok($lower) ? : 5 1 6
67 3 };
68  
69 5 ▶sub parse_move {
Subroutine parse_move: called CC=8 SCAR=22.2
Pod documented
70 5 my ($text) = @_;
71 5 ▶ return (undef, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 5 5
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
005
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
72 5 my @parts = split /-/, $text, -1;
73 5 ▶ return (undef, 'shape') unless @parts == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 0 5 5
74 5 my ($from, $to) = map { $place->($_) } @parts;
75 5 ▶ return (undef, 'place') unless defined $from && defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from and defined $to 1 4 5
Condition66%2/3
defined $from and defined $to
!ll&&!rl&&r
104
MC/DC50%1/2
defined $from and defined $to
defined $from defined $to
Truth table66%2/3
A and B
A= defined $fromB= defined $to
ABresult
0X0
100
111
76 4 ▶ return (undef, 'from_home') if $from eq 'home';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "home" 0 4 4
77 4 ▶ return (undef, 'to_hand') if $to eq 'hand';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "hand" 0 4 4
78 4 return ({ from => $from, to => $to }, undef);
79 }
80  
81 13 ▶my $read = sub {
Subroutine __ANON__: called CC=4 SCAR=16.1
82 13 my ($move, $name) = @_;
83 13 ▶ return $move->$name if Scalar::Util::blessed($move) && $move->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($move) and $move->can($name) 0 13 13
Condition33%1/3
builtin::blessed($move) and $move->can($name)
!ll&&!rl&&r
1300
MC/DC0%0/2
builtin::blessed($move) and $move->can($name)
builtin::blessed($move) $move->can($name)
Truth table33%1/3
A and B
A= builtin::blessed($move)B= $move->can($name)
ABresult
0X0
100
111
84 13 ▶ return ref $move eq 'HASH' ? $move->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $move eq 'HASH' ? : 13 0 13
85 3 };
86  
87 5 ▶sub format_move {
Subroutine format_move: called CC=1 SCAR=0.0
Pod documented
88 5 my ($move) = @_;
89 5 return $read->($move, 'from') . '-' . $read->($move, 'to');
90 }
91  
92 1 ▶sub format_display {
Subroutine format_display: called CC=4 SCAR=15.2
Pod documented
93 1 my ($move, $roll) = @_;
94 1 ▶ $roll = $read->($move, 'roll') unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 1 0 1
95 1 ▶ return $roll . ': ' . format_move($move)
Branch: 2 branches
BranchTrueFalseTotal
&$read($move, 'captures') ? : 1 0 1
&$read($move, 'rosette') ? : 1 0 1
96 . ($read->($move, 'captures') ? 'x' : '')
97 . ($read->($move, 'rosette') ? '*' : '');
98 }
99  
100 1 ▶sub format_forfeit {
Subroutine format_forfeit: called CC=1 SCAR=0.0
Pod documented
101 1 my ($roll) = @_;
102 1 return $roll . ': -';
103 }
104  
105 2 ▶sub validate_position {
Subroutine validate_position: called CC=35 SCAR=44.0
Pod documented
106 2 my ($text) = @_;
107 2 ▶ return POS_NULL unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 2 2
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
002
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
108 2 ▶ return POS_LONG if length $text >= 48;
Branch: 1 branch
BranchTrueFalseTotal
if length $text >= 48 0 2 2
109  
110 2 my @c = split //, $text;
111 2 my ($row, $file, $i) = (2, 0, 0);
112 2 ▶ my $gap = sub { $row != 1 && ($file == 4 || $file == 5) };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$row != 1 and $file == 4 || $file == 5 21 8 29
Condition100%6/6
$row != 1 && ($file == 4 || $file == 5)
!ll&&!rl&&r
8165
$file == 4 or $file == 5
l!l&&r!l&&!r
3216
MC/DC100%3/3
$row != 1 && ($file == 4 || $file == 5)
$row != 1 $file == 4 $file == 5
Truth table100%4/4
A && B or C
A= $row != 1B= $file == 4C= $file == 5
ABCresult
0XX0
1000
11X1
1011
113  
114 2 ▶ for (; $i < @c && $c[$i] ne ' '; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c and $c[$i] ne " ") 12 1 13
Condition66%2/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
0112
MC/DC50%1/2
$i < @c and $c[$i] ne " "
$i < @c $c[$i] ne " "
Truth table66%2/3
A and B
A= $i < @cB= $c[$i] ne " "
ABresult
0X0
100
111
115 12 my $ch = $c[$i];
116 12 ▶ if ($ch eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "/") 2 10 12
117 2 ▶ return POS_WIDTH if $file != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file != 8 0 2 2
118 2 ▶ return POS_ROWS if $row == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $row == 0 0 2 2
119 2 $row--;
120 2 $file = 0;
121 2 next;
122 }
123 10 ▶ if ($ch =~ /\A[1-8]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /\A[1-8]\z/) 6 4 10
124 6 for (1 .. $ch) {
125 25 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 0 25 25
126 25 ▶ return POS_GAP if $gap->();
Branch: 1 branch
BranchTrueFalseTotal
if &$gap() 1 24 25
127 24 $file++;
128 }
129 5 next;
130 }
131 4 ▶ if ($ch eq 'x') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "x") 4 0 4
132 4 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 0 4 4
133 4 ▶ return POS_X unless $gap->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$gap() 0 4 4
134 4 $file++;
135 4 next;
136 }
137 0 ▶ return POS_LETTER unless $ch eq 'l' || $ch eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
unless $ch eq "l" or $ch eq "d" 0 0 0
Condition0%0/3
$ch eq "l" or $ch eq "d"
l!l&&r!l&&!r
000
MC/DC0%0/2
$ch eq "l" or $ch eq "d"
$ch eq "l" $ch eq "d"
Truth table0%0/3
A or B
A= $ch eq "l"B= $ch eq "d"
ABresult
1X1
011
000
138 0 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 0 0 0
139 0 ▶ return POS_GAP if $gap->();
Branch: 1 branch
BranchTrueFalseTotal
if &$gap() 0 0 0
140 0 $file++;
141 }
142 1 ▶ return POS_ROWS if $row != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $row != 0 0 1 1
143 1 ▶ return POS_WIDTH if $file != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file != 8 0 1 1
144  
145 1 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 0 1 1
Condition33%1/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
001
MC/DC0%0/2
$i < @c and $c[$i] eq " "
$i < @c $c[$i] eq " "
Truth table33%1/3
A and B
A= $i < @cB= $c[$i] eq " "
ABresult
0X0
100
111
146 1 $i++;
147 1 ▶ return POS_SIDE unless $i < @c && ($c[$i] eq 'l' || $c[$i] eq 'd');
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq "l" || $c[$i] eq "d" 0 1 1
Condition33%2/6
$i < @c and $c[$i] eq "l" || $c[$i] eq "d"
!ll&&!rl&&r
001
$c[$i] eq "l" or $c[$i] eq "d"
l!l&&r!l&&!r
100
MC/DC0%0/3
$i < @c and $c[$i] eq "l" || $c[$i] eq "d"
$i < @c $c[$i] eq "l" $c[$i] eq "d"
Truth table25%1/4
A and B or C
A= $i < @cB= $c[$i] eq "l"C= $c[$i] eq "d"
ABCresult
0XX0
1000
11X1
1011
148 1 $i++;
149 1 for (1 .. 4) {
150 4 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 0 4 4
Condition33%1/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
004
MC/DC0%0/2
$i < @c and $c[$i] eq " "
$i < @c $c[$i] eq " "
Truth table33%1/3
A and B
A= $i < @cB= $c[$i] eq " "
ABresult
0X0
100
111
151 4 $i++;
152 4 ▶ return POS_FIELD if $i >= @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @c 0 4 4
153 4 ▶ return POS_COUNT unless $c[$i] =~ /\A[0-7]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $c[$i] =~ /\A[0-7]\z/ 0 4 4
154 4 $i++;
155 4 ▶ return POS_COUNT if $i < @c && $c[$i] ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c and $c[$i] ne " " 0 4 4
Condition66%2/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
130
MC/DC0%0/2
$i < @c and $c[$i] ne " "
$i < @c $c[$i] ne " "
Truth table66%2/3
A and B
A= $i < @cB= $c[$i] ne " "
ABresult
0X0
100
111
156 }
157 1 ▶ return POS_FIELD if $i < @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c 0 1 1
158 1 return POS_OK;
159 }
160  
161 2 ▶my $rules_text = sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
162 2 my ($rules) = @_;
163 2 ▶ return $rules unless ref $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rules 2 0 2
164 0 return join ' ', map { "$_=$rules->{$_}" } @FIELDS;
165 3 };
166  
167 3 ▶my $rules_of = sub {
Subroutine __ANON__: called CC=10 SCAR=44.2
168 3 my ($text) = @_;
169 3 ▶ return $text if exists $NAMED{$text};
Branch: 1 branch
BranchTrueFalseTotal
if exists $NAMED{$text} 3 0 3
170 0 my (%given, @names);
171 0 for my $pair (split / /, $text, -1) {
172 0 ▶ my ($name, $value) = $pair =~ /\A([a-z_]+)=([a-z0-9]+)\z/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
() = $pair =~ /\A([a-z_]+)=([a-z0-9]+)\z/ or return undef 0 0 0
173 0 push @names, $name;
174 0 $given{$name} = $value;
175 }
176 0 ▶ return undef unless "@names" eq "@FIELDS";
Branch: 1 branch
BranchTrueFalseTotal
unless join($", @names) eq join($", @FIELDS) 0 0 0
177 return undef unless $given{route} =~ /\A(?:short|long)\z/
178 && $given{dice} =~ /\A[34]\z/ && $given{zero_rolls} =~ /\A[04]\z/
179 0 ▶ && $given{safe_rosettes} =~ /\A[01]\z/ && $given{pieces} =~ /\A[1-7]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/ and $given{"zero_rolls"} =~ /\A[04]\z/ and $given{"safe_rosettes"} =~ /\A[01]\z/ and $given{"pieces"} =~ /\A[1-7]\z/ 0 0 0
Condition0%0/12
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/ and $given{"zero_rolls"} =~ /\A[04]\z/ and $given{"safe_rosettes"} =~ /\A[01]\z/ and $given{"pieces"} =~ /\A[1-7]\z/
!ll&&!rl&&r
000
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/ and $given{"zero_rolls"} =~ /\A[04]\z/ and $given{"safe_rosettes"} =~ /\A[01]\z/
!ll&&!rl&&r
000
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/ and $given{"zero_rolls"} =~ /\A[04]\z/
!ll&&!rl&&r
000
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/
!ll&&!rl&&r
000
MC/DC0%0/5
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/ and $given{"zero_rolls"} =~ /\A[04]\z/ and $given{"safe_rosettes"} =~ /\A[01]\z/ and $given{"pieces"} =~ /\A[1-7]\z/
$given{"route"} =~ /\A(?:short|long)\z/ $given{"dice"} =~ /\A[34]\z/ $given{"zero_rolls"} =~ /\A[04]\z/ $given{"safe_rosettes"} =~ /\A[01]\z/ $given{"pieces"} =~ /\A[1-7]\z/
Truth table0%0/6
A and B and C and D and E
A= $given{"route"} =~ /\A(?:short|long)\z/B= $given{"dice"} =~ /\A[34]\z/C= $given{"zero_rolls"} =~ /\A[04]\z/D= $given{"safe_rosettes"} =~ /\A[01]\z/E= $given{"pieces"} =~ /\A[1-7]\z/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
180 0 return \%given;
181 3 };
182  
183 3 ▶my $spelled = sub { ref $_[0] ? $_[0] : $NAMED{ $_[0] } };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 3 3
184  
185 2 ▶sub format_record {
Subroutine format_record: called CC=9 SCAR=22.3
Pod documented
186 2 my ($record) = @_;
187 my @lines = (
188 '[rules ' . $rules_text->($record->{rules}) . ']',
189 2 '[first ' . $record->{first} . ']',
190 );
191 2 ▶ push @lines, '[position ' . $record->{position} . ']' if defined $record->{position};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"position"} 0 2 2
192 2 ▶ push @lines, '[seed ' . $record->{seed} . ']' if defined $record->{seed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"seed"} 1 1 2
193 2 ▶ push @lines, '[opening ' . $record->{opening} . ']' if $record->{opening};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"opening"} 0 2 2
194 2 my $n = 0;
195 2 ▶ for my $turn (@{ $record->{turns} || [] }) {
Condition50%1/2
$record->{'turns'} || []
l!l
20
MC/DC0%0/1
$record->{'turns'} || []
$record->{'turns'}
Truth table50%1/2
A
A= $record->{'turns'}
Aresult
11
00
196 3 $n++;
197 push @lines, $n . '. ' . $LETTER_OF{ $turn->{side} } . ' ' . $turn->{roll}
198 . (defined $turn->{faces} ? ' ' . $turn->{faces} : '')
199 3 ▶ . ': ' . (defined $turn->{move} ? $turn->{move} : '-');
Branch: 2 branches
BranchTrueFalseTotal
defined $turn->{'faces'} ? : 0 3 3
defined $turn->{'move'} ? : 2 1 3
200 }
201 push @lines, '[result ' . $record->{result}{winner} . ' ' . $record->{result}{how} . ']'
202 2 ▶ if $record->{result};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"result"} 1 1 2
203 2 return join("\n", @lines) . "\n";
204 }
205  
206 3 ▶sub parse_record {
Subroutine parse_record: called CC=37 SCAR=42.8
Pod documented
207 3 my ($text) = @_;
208 3 ▶ my $fail = sub { return (undef, { line => $_[0], error => $_[1] }) };
Subroutine __ANON__: called CC=1 SCAR=0.0
209 3 ▶ return $fail->(0, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 3 3
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
003
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
210 3 ▶ return $fail->(0, 'no_newline') unless $text =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\n\z/ 0 3 3
211  
212 3 my @lines = split /\n/, $text, -1;
213 3 pop @lines;
214 3 my %record = (turns => []);
215 3 my ($at, $expect, $done) = (0, undef, 0);
216  
217 15 ▶ my $header = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
218 15 my ($name, $pattern) = @_;
219 15 ▶ return undef unless $at < @lines && $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/ 8 7 15
Condition100%3/3
$at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
!ll&&!rl&&r
177
MC/DC100%2/2
$at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
$at < @lines $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
Truth table100%3/3
A and B
A= $at < @linesB= $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
ABresult
0X0
100
111
220 7 $at++;
221 7 return $1;
222 3 };
223  
224 3 my $rules = $header->('rules', '[a-z0-9_= ]+');
225 3 ▶ return $fail->($at + 1, 'rules') unless defined $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rules 0 3 3
226 3 $record{rules} = $rules_of->($rules);
227 3 ▶ return $fail->($at, 'rules') unless defined $record{rules};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"rules"} 0 3 3
228 3 my $set = $spelled->($record{rules});
229  
230 3 $record{first} = $header->('first', 'light|dark');
231 3 ▶ return $fail->($at + 1, 'first') unless defined $record{first};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"first"} 0 3 3
232  
233 3 my $position = $header->('position', '[0-9xld/ ]+');
234 3 ▶ return $fail->($at, 'position') if defined $position && validate_position($position);
Branch: 1 branch
BranchTrueFalseTotal
if defined $position and validate_position($position) 0 3 3
Condition33%1/3
defined $position and validate_position($position)
!ll&&!rl&&r
300
MC/DC0%0/2
defined $position and validate_position($position)
defined $position validate_position($position)
Truth table33%1/3
A and B
A= defined $positionB= validate_position($position)
ABresult
0X0
100
111
235 3 ▶ $record{position} = $position if defined $position;
Branch: 1 branch
BranchTrueFalseTotal
if defined $position 0 3 3
236  
237 3 my $seed = $header->('seed', '(?:[0-9a-f]{2})+');
238 3 ▶ $record{seed} = $seed if defined $seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seed 1 2 3
239 3 my $opening = $header->('opening', '[1-9][0-9]*');
240 3 ▶ $record{opening} = $opening + 0 if defined $opening;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opening 0 3 3
241 3 ▶ return $fail->($at, 'opening') if defined $opening && ($opening % 2 || !defined $seed);
Branch: 1 branch
BranchTrueFalseTotal
if defined $opening and $opening % 2 || !defined($seed) 0 3 3
Condition16%1/6
defined $opening and $opening % 2 || !defined($seed)
!ll&&!rl&&r
300
$opening % 2 or not defined $seed
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $opening and $opening % 2 || !defined($seed)
defined $opening $opening % 2 not defined $seed
Truth table25%1/4
A and B or not(C)
A= defined $openingB= $opening % 2C= not defined $seed
ABCresult
0XX0
1000
11X1
1011
242  
243 3 ▶ my $bytes = defined $seed ? pack('H*', $seed) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $seed ? : 1 2 3
244 3 ▶ my $throw = $record{opening} || 0;
Condition50%1/2
$record{'opening'} || 0
l!l
03
MC/DC0%0/1
$record{'opening'} || 0
$record{'opening'}
Truth table50%1/2
A
A= $record{'opening'}
Aresult
11
00
245 3 $expect = $record{first};
246  
247 3 ▶ for (; $at < @lines; $at++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @lines) 6 2 8
248 6 my $line = $lines[$at];
249 6 my $number = $at + 1;
250 6 ▶ return $fail->($number, 'after_result') if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 6 6
251  
252 6 ▶ if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) 1 5 6
253 1 ▶ return $fail->($number, 'result') unless $RESULT_OK{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless $RESULT_OK{$1} 0 1 1
254 1 my ($winner, $how) = split / /, $1;
255 1 $record{result} = { winner => $winner, how => $how };
256 1 $done = 1;
257 1 next;
258 }
259  
260 5 ▶ my ($n, $letter, $roll, $faces, $move) =
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ /\A([1-9][0-9]*)\. ([ld]) ([0-4])(?: ([01]{3,4}))?: (\S+)\z/ or return &$fail($number, "turn") 5 0 5
261 $line =~ /\A([1-9][0-9]*)\. ([ld]) ([0-4])(?: ([01]{3,4}))?: (\S+)\z/
262 or return $fail->($number, 'turn');
263 5 ▶ return $fail->($number, 'number') unless $n == @{ $record{turns} } + 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @{$record{"turns"};} + 1 0 5 5
264  
265 5 my $side = $SIDE_OF{$letter};
266 5 ▶ return $fail->($number, 'side') unless $side eq $expect;
Branch: 1 branch
BranchTrueFalseTotal
unless $side eq $expect 1 4 5
267  
268 4 ▶ if (defined $faces) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $faces) 0 4 4
269 0 ▶ return $fail->($number, 'faces') unless length $faces == $set->{dice};
Branch: 1 branch
BranchTrueFalseTotal
unless length $faces == $set->{"dice"} 0 0 0
270 0 my $marked = ($faces =~ tr/1//);
271 0 ▶ return $fail->($number, 'faces')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::RoyalUr::Dice::roll_of($marked, $set) == $roll 0 0 0
272 unless Game::RoyalUr::Dice::roll_of($marked, $set) == $roll;
273 }
274 4 ▶ if (defined $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bytes) 0 4 4
275 0 my $thrown = Game::RoyalUr::Dice::throw_for($bytes, $throw, $set->{dice});
276 0 ▶ return $fail->($number, 'roll')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($thrown), $set) == $roll 0 0 0
277 unless Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($thrown), $set) == $roll;
278 0 ▶ return $fail->($number, 'faces') if defined $faces && $faces ne join('', @$thrown);
Branch: 1 branch
BranchTrueFalseTotal
if defined $faces and $faces ne join("", @$thrown) 0 0 0
Condition0%0/3
defined $faces and $faces ne join("", @$thrown)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $faces and $faces ne join("", @$thrown)
defined $faces $faces ne join("", @$thrown)
Truth table0%0/3
A and B
A= defined $facesB= $faces ne join("", @$thrown)
ABresult
0X0
100
111
279 }
280 4 $throw++;
281  
282 4 my %turn = (side => $side, roll => $roll + 0);
283 4 ▶ $turn{faces} = $faces if defined $faces;
Branch: 1 branch
BranchTrueFalseTotal
if defined $faces 0 4 4
284 4 ▶ my $other = $side eq 'light' ? 'dark' : 'light';
Branch: 1 branch
BranchTrueFalseTotal
$side eq 'light' ? : 3 1 4
285 4 ▶ if ($move eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move eq '-') { } 1 3 4
286 1 $turn{move} = undef;
287 1 $expect = $other;
288 }
289 else {
290 3 my ($parsed, $error) = parse_move($move);
291 3 ▶ return $fail->($number, 'move') unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 0 3 3
292 3 ▶ return $fail->($number, 'move') unless $move eq format_move($parsed);
Branch: 1 branch
BranchTrueFalseTotal
unless $move eq format_move($parsed) 0 3 3
293 3 $turn{move} = $move;
294 3 ▶ $expect = $ROSETTE{ $parsed->{to} } ? $side : $other;
Branch: 1 branch
BranchTrueFalseTotal
$ROSETTE{$parsed->{'to'}} ? : 2 1 3
295 }
296 4 push @{ $record{turns} }, \%turn;
297 }
298 2 return (\%record, undef);
299 }
300  
301 3 1;
302  
303 __END__
↑ Summary blib/lib/Game/RoyalUr/Dice.pm »