blib/lib/Game/RoyalUr/Notation.pm

filter: Statementstmt 100% 226 / 226 Branchbran 98.7% 158 / 160 Conditioncond 89.4% 68 / 76 MC/DCmcdc 81.8% 36 / 44 Subroutinesub 100% 31 / 31 Podpod 100% 8 / 8 totaltotal 96.7% 527 / 545 CC 110 SCAR 29.7
CC
110
Cov
98%
validate_position
35.0
parse_record
34.0
__ANON__
10.2
CRAP 19.5
↑ Summary blib/lib/Game/RoyalUr/Terminal.pm »
1 package Game::RoyalUr::Notation;
2  
3 58 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 58 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 58 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 58 ▶use Exporter 'import';
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 58 ▶use Scalar::Util ();
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 58 ▶use Game::RoyalUr::Dice ();
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 60 our $VERSION = '0.02';
13  
14 58 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 58 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 58 };
27  
28 60 our (@EXPORT_OK, %EXPORT_TAGS);
29 60 my (%MISSING, %ROSETTE, %NAMED, @FIELDS, %SIDE_OF, %LETTER_OF, %RESULT_OK);
30 60 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 60 @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 60 %EXPORT_TAGS = (all => \@EXPORT_OK);
38  
39 60 %MISSING = map { $_ => 1 } qw(e1 f1 e3 f3);
40 60 %ROSETTE = map { $_ => 1 } qw(a1 g1 a3 g3 d2);
41 60 %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 60 @FIELDS = qw(route dice zero_rolls safe_rosettes pieces);
46 60 %SIDE_OF = (l => 'light', d => 'dark');
47 60 %LETTER_OF = (light => 'l', dark => 'd');
48 60 %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 533773 ▶sub square_ok {
Subroutine square_ok: called CC=4 SCAR=13.9
Pod documented
56 533773 my ($name) = @_;
57 533773 ▶ 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/ 9 533764 533773
Condition100%3/3
defined $name and $name =~ /\A[a-h][1-3]\z/
!ll&&!rl&&r
18533764
MC/DC100%2/2
defined $name and $name =~ /\A[a-h][1-3]\z/
defined $name $name =~ /\A[a-h][1-3]\z/
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /\A[a-h][1-3]\z/
ABresult
0X0
100
111
58 533764 ▶ return $MISSING{$name} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$MISSING{$name} ? : 3141 530623 533764
59 }
60  
61 500388 ▶my $place = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
62 500388 my ($text) = @_;
63 500388 my $lower = lc $text;
64 500388 ▶ return $lower if $lower eq 'hand' || $lower eq 'home';
Branch: 1 branch
BranchTrueFalseTotal
if $lower eq "hand" or $lower eq "home" 57257 443131 500388
Condition100%3/3
$lower eq "hand" or $lower eq "home"
l!l&&r!l&&!r
4283614421443131
MC/DC100%2/2
$lower eq "hand" or $lower eq "home"
$lower eq "hand" $lower eq "home"
Truth table100%3/3
A or B
A= $lower eq "hand"B= $lower eq "home"
ABresult
1X1
011
000
65 443131 ▶ return undef unless $text =~ /\A[A-Ha-h][1-3]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\A[A-Ha-h][1-3]\z/ 10 443121 443131
66 443121 ▶ return square_ok($lower) ? $lower : undef;
Branch: 1 branch
BranchTrueFalseTotal
square_ok($lower) ? : 443117 4 443121
67 60 };
68  
69 256538 ▶sub parse_move {
Subroutine parse_move: called CC=8 SCAR=20.8
Pod documented
70 256538 my ($text) = @_;
71 256538 ▶ return (undef, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 3 256535 256538
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
12256535
MC/DC100%2/2
defined $text and length $text
defined $text length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
72 256535 my @parts = split /-/, $text, -1;
73 256535 ▶ return (undef, 'shape') unless @parts == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 6341 250194 256535
74 250194 my ($from, $to) = map { $place->($_) } @parts;
75 250194 ▶ return (undef, 'place') unless defined $from && defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from and defined $to 14 250180 250194
Condition100%3/3
defined $from and defined $to
!ll&&!rl&&r
86250180
MC/DC100%2/2
defined $from and defined $to
defined $from defined $to
Truth table100%3/3
A and B
A= defined $fromB= defined $to
ABresult
0X0
100
111
76 250180 ▶ return (undef, 'from_home') if $from eq 'home';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "home" 1 250179 250180
77 250179 ▶ return (undef, 'to_hand') if $to eq 'hand';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "hand" 3 250176 250179
78 250176 return ({ from => $from, to => $to }, undef);
79 }
80  
81 481181 ▶my $read = sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
82 481181 my ($move, $name) = @_;
83 481181 ▶ return $move->$name if Scalar::Util::blessed($move) && $move->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($move) and $move->can($name) 306562 174619 481181
Condition66%2/3
builtin::blessed($move) and $move->can($name)
!ll&&!rl&&r
1746190306562
MC/DC50%1/2
builtin::blessed($move) and $move->can($name)
builtin::blessed($move) $move->can($name)
Truth table66%2/3
A and B
A= builtin::blessed($move)B= $move->can($name)
ABresult
0X0
100
111
84 174619 ▶ return ref $move eq 'HASH' ? $move->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $move eq 'HASH' ? : 174619 0 174619
85 60 };
86  
87 173856 ▶sub format_move {
Subroutine format_move: called CC=1 SCAR=0.0
Pod documented
88 173856 my ($move) = @_;
89 173856 return $read->($move, 'from') . '-' . $read->($move, 'to');
90 }
91  
92 44490 ▶sub format_display {
Subroutine format_display: called CC=4 SCAR=13.9
Pod documented
93 44490 my ($move, $roll) = @_;
94 44490 ▶ $roll = $read->($move, 'roll') unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 44489 1 44490
95 44490 ▶ return $roll . ': ' . format_move($move)
Branch: 2 branches
BranchTrueFalseTotal
&$read($move, 'captures') ? : 5679 38811 44490
&$read($move, 'rosette') ? : 9673 34817 44490
96 . ($read->($move, 'captures') ? 'x' : '')
97 . ($read->($move, 'rosette') ? '*' : '');
98 }
99  
100 7 ▶sub format_forfeit {
Subroutine format_forfeit: called CC=1 SCAR=0.0
Pod documented
101 7 my ($roll) = @_;
102 7 return $roll . ': -';
103 }
104  
105 721 ▶sub validate_position {
Subroutine validate_position: called CC=35 SCAR=35.6
Pod documented
106 721 my ($text) = @_;
107 721 ▶ return POS_NULL unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 2 719 721
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
11719
MC/DC100%2/2
defined $text and length $text
defined $text length $text
Truth table100%3/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
108 719 ▶ return POS_LONG if length $text >= 48;
Branch: 1 branch
BranchTrueFalseTotal
if length $text >= 48 1 718 719
109  
110 718 my @c = split //, $text;
111 718 my ($row, $file, $i) = (2, 0, 0);
112 718 ▶ 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 11138 5559 16697
Condition100%6/6
$row != 1 && ($file == 4 || $file == 5)
!ll&&!rl&&r
555983562782
$file == 4 or $file == 5
l!l&&r!l&&!r
139413888356
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 718 ▶ for (; $i < @c && $c[$i] ne ' '; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c and $c[$i] ne " ") 15170 688 15858
Condition100%3/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
368515170
MC/DC100%2/2
$i < @c and $c[$i] ne " "
$i < @c $c[$i] ne " "
Truth table100%3/3
A and B
A= $i < @cB= $c[$i] ne " "
ABresult
0X0
100
111
115 15170 my $ch = $c[$i];
116 15170 ▶ if ($ch eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "/") 1396 13774 15170
117 1396 ▶ return POS_WIDTH if $file != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file != 8 6 1390 1396
118 1390 ▶ return POS_ROWS if $row == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $row == 0 1 1389 1390
119 1389 $row--;
120 1389 $file = 0;
121 1389 next;
122 }
123 13774 ▶ if ($ch =~ /\A[1-8]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /\A[1-8]\z/) 3720 10054 13774
124 3720 for (1 .. $ch) {
125 6653 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 3 6650 6653
126 6650 ▶ return POS_GAP if $gap->();
Branch: 1 branch
BranchTrueFalseTotal
if &$gap() 6 6644 6650
127 6644 $file++;
128 }
129 3711 next;
130 }
131 10054 ▶ if ($ch eq 'x') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "x") 2779 7275 10054
132 2779 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 0 2779 2779
133 2779 ▶ return POS_X unless $gap->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$gap() 5 2774 2779
134 2774 $file++;
135 2774 next;
136 }
137 7275 ▶ return POS_LETTER unless $ch eq 'l' || $ch eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
unless $ch eq "l" or $ch eq "d" 6 7269 7275
Condition100%3/3
$ch eq "l" or $ch eq "d"
l!l&&r!l&&!r
369235776
MC/DC100%2/2
$ch eq "l" or $ch eq "d"
$ch eq "l" $ch eq "d"
Truth table100%3/3
A or B
A= $ch eq "l"B= $ch eq "d"
ABresult
1X1
011
000
138 7269 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 1 7268 7269
139 7268 ▶ return POS_GAP if $gap->();
Branch: 1 branch
BranchTrueFalseTotal
if &$gap() 2 7266 7268
140 7266 $file++;
141 }
142 688 ▶ return POS_ROWS if $row != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $row != 0 5 683 688
143 683 ▶ return POS_WIDTH if $file != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file != 8 1 682 683
144  
145 682 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 1 681 682
Condition66%2/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
10681
MC/DC50%1/2
$i < @c and $c[$i] eq " "
$i < @c $c[$i] eq " "
Truth table66%2/3
A and B
A= $i < @cB= $c[$i] eq " "
ABresult
0X0
100
111
146 681 $i++;
147 681 ▶ 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" 5 676 681
Condition100%6/6
$i < @c and $c[$i] eq "l" || $c[$i] eq "d"
!ll&&!rl&&r
14676
$c[$i] eq "l" or $c[$i] eq "d"
l!l&&r!l&&!r
4242524
MC/DC100%3/3
$i < @c and $c[$i] eq "l" || $c[$i] eq "d"
$i < @c $c[$i] eq "l" $c[$i] eq "d"
Truth table100%4/4
A and B or C
A= $i < @cB= $c[$i] eq "l"C= $c[$i] eq "d"
ABCresult
0XX0
1000
11X1
1011
148 676 $i++;
149 676 for (1 .. 4) {
150 2675 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 5 2670 2675
Condition100%3/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
322670
MC/DC100%2/2
$i < @c and $c[$i] eq " "
$i < @c $c[$i] eq " "
Truth table100%3/3
A and B
A= $i < @cB= $c[$i] eq " "
ABresult
0X0
100
111
151 2670 $i++;
152 2670 ▶ return POS_FIELD if $i >= @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @c 2 2668 2670
153 2668 ▶ return POS_COUNT unless $c[$i] =~ /\A[0-7]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $c[$i] =~ /\A[0-7]\z/ 5 2663 2668
154 2663 $i++;
155 2663 ▶ return POS_COUNT if $i < @c && $c[$i] ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c and $c[$i] ne " " 4 2659 2663
Condition100%3/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
66019994
MC/DC100%2/2
$i < @c and $c[$i] ne " "
$i < @c $c[$i] ne " "
Truth table100%3/3
A and B
A= $i < @cB= $c[$i] ne " "
ABresult
0X0
100
111
156 }
157 660 ▶ return POS_FIELD if $i < @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c 2 658 660
158 658 return POS_OK;
159 }
160  
161 905 ▶my $rules_text = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
162 905 my ($rules) = @_;
163 905 ▶ return $rules unless ref $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rules 894 11 905
164 11 return join ' ', map { "$_=$rules->{$_}" } @FIELDS;
165 60 };
166  
167 536 ▶my $rules_of = sub {
Subroutine __ANON__: called CC=10 SCAR=23.3
168 536 my ($text) = @_;
169 536 ▶ return $text if exists $NAMED{$text};
Branch: 1 branch
BranchTrueFalseTotal
if exists $NAMED{$text} 521 15 536
170 15 my (%given, @names);
171 15 for my $pair (split / /, $text, -1) {
172 71 ▶ 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 70 1 71
173 70 push @names, $name;
174 70 $given{$name} = $value;
175 }
176 14 ▶ return undef unless "@names" eq "@FIELDS";
Branch: 1 branch
BranchTrueFalseTotal
unless join($", @names) eq join($", @FIELDS) 1 13 14
177 return undef unless $given{route} =~ /\A(?:short|long)\z/
178 && $given{dice} =~ /\A[34]\z/ && $given{zero_rolls} =~ /\A[04]\z/
179 13 ▶ && $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/ 1 12 13
Condition66%8/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
1012
$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
1012
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/ and $given{"zero_rolls"} =~ /\A[04]\z/
!ll&&!rl&&r
1012
$given{"route"} =~ /\A(?:short|long)\z/ and $given{"dice"} =~ /\A[34]\z/
!ll&&!rl&&r
0112
MC/DC20%1/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 table33%2/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 12 return \%given;
181 60 };
182  
183 533 ▶my $spelled = sub { ref $_[0] ? $_[0] : $NAMED{ $_[0] } };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 12 521 533
184  
185 905 ▶sub format_record {
Subroutine format_record: called CC=8 SCAR=20.8
Pod documented
186 905 my ($record) = @_;
187 my @lines = (
188 '[rules ' . $rules_text->($record->{rules}) . ']',
189 905 '[first ' . $record->{first} . ']',
190 );
191 905 ▶ push @lines, '[seed ' . $record->{seed} . ']' if defined $record->{seed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"seed"} 900 5 905
192 905 ▶ push @lines, '[opening ' . $record->{opening} . ']' if $record->{opening};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"opening"} 429 476 905
193 905 my $n = 0;
194 905 ▶ for my $turn (@{ $record->{turns} || [] }) {
Condition50%1/2
$record->{'turns'} || []
l!l
9050
MC/DC0%0/1
$record->{'turns'} || []
$record->{'turns'}
Truth table50%1/2
A
A= $record->{'turns'}
Aresult
11
00
195 165917 $n++;
196 push @lines, $n . '. ' . $LETTER_OF{ $turn->{side} } . ' ' . $turn->{roll}
197 . (defined $turn->{faces} ? ' ' . $turn->{faces} : '')
198 165917 ▶ . ': ' . (defined $turn->{move} ? $turn->{move} : '-');
Branch: 2 branches
BranchTrueFalseTotal
defined $turn->{'faces'} ? : 165882 35 165917
defined $turn->{'move'} ? : 159187 6730 165917
199 }
200 push @lines, '[result ' . $record->{result}{winner} . ' ' . $record->{result}{how} . ']'
201 905 ▶ if $record->{result};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"result"} 890 15 905
202 905 return join("\n", @lines) . "\n";
203 }
204  
205 580 ▶sub parse_record {
Subroutine parse_record: called CC=34 SCAR=35.3
Pod documented
206 580 my ($text) = @_;
207 580 ▶ my $fail = sub { return (undef, { line => $_[0], error => $_[1] }) };
Subroutine __ANON__: called CC=1 SCAR=0.0
208 580 ▶ return $fail->(0, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 1 579 580
Condition66%2/3
defined $text and length $text
!ll&&!rl&&r
01579
MC/DC50%1/2
defined $text and length $text
defined $text length $text
Truth table66%2/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
209 579 ▶ return $fail->(0, 'no_newline') unless $text =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\n\z/ 1 578 579
210  
211 578 my @lines = split /\n/, $text, -1;
212 578 pop @lines;
213 578 my %record = (turns => []);
214 578 my ($at, $expect, $done) = (0, undef, 0);
215  
216 2173 ▶ my $header = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
217 2173 my ($name, $pattern) = @_;
218 2173 ▶ 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/ 376 1797 2173
Condition100%3/3
$at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
!ll&&!rl&&r
13751797
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
219 1797 $at++;
220 1797 return $1;
221 578 };
222  
223 578 my $rules = $header->('rules', '[a-z0-9_= ]+');
224 578 ▶ return $fail->($at + 1, 'rules') unless defined $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rules 42 536 578
225 536 $record{rules} = $rules_of->($rules);
226 536 ▶ return $fail->($at, 'rules') unless defined $record{rules};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"rules"} 3 533 536
227 533 my $set = $spelled->($record{rules});
228  
229 533 $record{first} = $header->('first', 'light|dark');
230 533 ▶ return $fail->($at + 1, 'first') unless defined $record{first};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"first"} 2 531 533
231  
232 531 my $seed = $header->('seed', '(?:[0-9a-f]{2})+');
233 531 ▶ $record{seed} = $seed if defined $seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seed 499 32 531
234 531 my $opening = $header->('opening', '[1-9][0-9]*');
235 531 ▶ $record{opening} = $opening + 0 if defined $opening;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opening 231 300 531
236 531 ▶ return $fail->($at, 'opening') if defined $opening && ($opening % 2 || !defined $seed);
Branch: 1 branch
BranchTrueFalseTotal
if defined $opening and $opening % 2 || !defined($seed) 2 529 531
Condition100%6/6
defined $opening and $opening % 2 || !defined($seed)
!ll&&!rl&&r
3002292
$opening % 2 or not defined $seed
l!l&&r!l&&!r
11229
MC/DC100%3/3
defined $opening and $opening % 2 || !defined($seed)
defined $opening $opening % 2 not defined $seed
Truth table100%4/4
A and B or not(C)
A= defined $openingB= $opening % 2C= not defined $seed
ABCresult
0XX0
1000
11X1
1011
237  
238 529 ▶ my $bytes = defined $seed ? pack('H*', $seed) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $seed ? : 498 31 529
239 529 ▶ my $throw = $record{opening} || 0;
Condition100%2/2
$record{'opening'} || 0
l!l
229300
MC/DC100%1/1
$record{'opening'} || 0
$record{'opening'}
Truth table100%2/2
A
A= $record{'opening'}
Aresult
11
00
240 529 $expect = $record{first};
241  
242 529 ▶ for (; $at < @lines; $at++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @lines) 89783 506 90289
243 89783 my $line = $lines[$at];
244 89783 my $number = $at + 1;
245 89783 ▶ return $fail->($number, 'after_result') if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 1 89782 89783
246  
247 89782 ▶ if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) 490 89292 89782
248 490 ▶ return $fail->($number, 'result') unless $RESULT_OK{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless $RESULT_OK{$1} 2 488 490
249 488 my ($winner, $how) = split / /, $1;
250 488 $record{result} = { winner => $winner, how => $how };
251 488 $done = 1;
252 488 next;
253 }
254  
255 89292 ▶ 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") 89289 3 89292
256 $line =~ /\A([1-9][0-9]*)\. ([ld]) ([0-4])(?: ([01]{3,4}))?: (\S+)\z/
257 or return $fail->($number, 'turn');
258 89289 ▶ return $fail->($number, 'number') unless $n == @{ $record{turns} } + 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @{$record{"turns"};} + 1 2 89287 89289
259  
260 89287 my $side = $SIDE_OF{$letter};
261 89287 ▶ return $fail->($number, 'side') unless $side eq $expect;
Branch: 1 branch
BranchTrueFalseTotal
unless $side eq $expect 6 89281 89287
262  
263 89281 ▶ if (defined $faces) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $faces) 89225 56 89281
264 89225 ▶ return $fail->($number, 'faces') unless length $faces == $set->{dice};
Branch: 1 branch
BranchTrueFalseTotal
unless length $faces == $set->{"dice"} 1 89224 89225
265 89224 my $marked = ($faces =~ tr/1//);
266 89224 ▶ return $fail->($number, 'faces')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::RoyalUr::Dice::roll_of($marked, $set) == $roll 2 89222 89224
267 unless Game::RoyalUr::Dice::roll_of($marked, $set) == $roll;
268 }
269 89278 ▶ if (defined $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bytes) 89186 92 89278
270 89186 my $thrown = Game::RoyalUr::Dice::throw_for($bytes, $throw, $set->{dice});
271 89186 ▶ return $fail->($number, 'roll')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($thrown), $set) == $roll 2 89184 89186
272 unless Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($thrown), $set) == $roll;
273 89184 ▶ return $fail->($number, 'faces') if defined $faces && $faces ne join('', @$thrown);
Branch: 1 branch
BranchTrueFalseTotal
if defined $faces and $faces ne join("", @$thrown) 1 89183 89184
Condition100%3/3
defined $faces and $faces ne join("", @$thrown)
!ll&&!rl&&r
16891671
MC/DC100%2/2
defined $faces and $faces ne join("", @$thrown)
defined $faces $faces ne join("", @$thrown)
Truth table100%3/3
A and B
A= defined $facesB= $faces ne join("", @$thrown)
ABresult
0X0
100
111
274 }
275 89275 $throw++;
276  
277 89275 my %turn = (side => $side, roll => $roll + 0);
278 89275 ▶ $turn{faces} = $faces if defined $faces;
Branch: 1 branch
BranchTrueFalseTotal
if defined $faces 89221 54 89275
279 89275 ▶ my $other = $side eq 'light' ? 'dark' : 'light';
Branch: 1 branch
BranchTrueFalseTotal
$side eq 'light' ? : 44719 44556 89275
280 89275 ▶ if ($move eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move eq '-') { } 3625 85650 89275
281 3625 $turn{move} = undef;
282 3625 $expect = $other;
283 }
284 else {
285 85650 my ($parsed, $error) = parse_move($move);
286 85650 ▶ return $fail->($number, 'move') unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 2 85648 85650
287 85648 ▶ return $fail->($number, 'move') unless $move eq format_move($parsed);
Branch: 1 branch
BranchTrueFalseTotal
unless $move eq format_move($parsed) 1 85647 85648
288 85647 $turn{move} = $move;
289 85647 ▶ $expect = $ROSETTE{ $parsed->{to} } ? $side : $other;
Branch: 1 branch
BranchTrueFalseTotal
$ROSETTE{$parsed->{'to'}} ? : 18007 67640 85647
290 }
291 89272 push @{ $record{turns} }, \%turn;
292 }
293 506 return (\%record, undef);
294 }
295  
296 60 1;
297  
298 __END__
↑ Summary blib/lib/Game/RoyalUr/Terminal.pm »