blib/lib/Game/RoyalUr/Notation.pm

filter: Statementstmt 100% 230 / 230 Branchbran 98.8% 164 / 166 Conditioncond 89.8% 71 / 79 MC/DCmcdc 82.6% 38 / 46 Subroutinesub 100% 31 / 31 Podpod 100% 8 / 8 totaltotal 96.7% 542 / 560 CC 114 SCAR 30.2
CC
114
Cov
98%
parse_record
37.0
validate_position
35.0
__ANON__
10.2
CRAP 20.5
↑ Summary blib/lib/Game/RoyalUr/Terminal.pm »
1 package Game::RoyalUr::Notation;
2  
3 81 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 81 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 81 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 81 ▶use Exporter 'import';
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 81 ▶use Scalar::Util ();
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 81 ▶use Game::RoyalUr::Dice ();
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 83 our $VERSION = '0.04';
13  
14 81 ▶use constant {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 81 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 81 };
27  
28 83 our (@EXPORT_OK, %EXPORT_TAGS);
29 83 my (%MISSING, %ROSETTE, %NAMED, @FIELDS, %SIDE_OF, %LETTER_OF, %RESULT_OK);
30 83 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 83 @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 83 %EXPORT_TAGS = (all => \@EXPORT_OK);
38  
39 83 %MISSING = map { $_ => 1 } qw(e1 f1 e3 f3);
40 83 %ROSETTE = map { $_ => 1 } qw(a1 g1 a3 g3 d2);
41 83 %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 83 @FIELDS = qw(route dice zero_rolls safe_rosettes pieces);
46 83 %SIDE_OF = (l => 'light', d => 'dark');
47 83 %LETTER_OF = (light => 'l', dark => 'd');
48 83 %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 575386 ▶sub square_ok {
Subroutine square_ok: called CC=4 SCAR=13.9
Pod documented
56 575386 my ($name) = @_;
57 575386 ▶ 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 575377 575386
Condition100%3/3
defined $name and $name =~ /\A[a-h][1-3]\z/
!ll&&!rl&&r
18575377
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 575377 ▶ return $MISSING{$name} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$MISSING{$name} ? : 6237 569140 575377
59 }
60  
61 518190 ▶my $place = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
62 518190 my ($text) = @_;
63 518190 my $lower = lc $text;
64 518190 ▶ return $lower if $lower eq 'hand' || $lower eq 'home';
Branch: 1 branch
BranchTrueFalseTotal
if $lower eq "hand" or $lower eq "home" 59762 458428 518190
Condition100%3/3
$lower eq "hand" or $lower eq "home"
l!l&&r!l&&!r
4482314939458428
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 458428 ▶ 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 458418 458428
66 458418 ▶ return square_ok($lower) ? $lower : undef;
Branch: 1 branch
BranchTrueFalseTotal
square_ok($lower) ? : 458414 4 458418
67 83 };
68  
69 265439 ▶sub parse_move {
Subroutine parse_move: called CC=8 SCAR=20.8
Pod documented
70 265439 my ($text) = @_;
71 265439 ▶ return (undef, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 3 265436 265439
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
12265436
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 265436 my @parts = split /-/, $text, -1;
73 265436 ▶ return (undef, 'shape') unless @parts == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 6341 259095 265436
74 259095 my ($from, $to) = map { $place->($_) } @parts;
75 259095 ▶ return (undef, 'place') unless defined $from && defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from and defined $to 14 259081 259095
Condition100%3/3
defined $from and defined $to
!ll&&!rl&&r
86259081
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 259081 ▶ return (undef, 'from_home') if $from eq 'home';
Branch: 1 branch
BranchTrueFalseTotal
if $from eq "home" 1 259080 259081
77 259080 ▶ return (undef, 'to_hand') if $to eq 'hand';
Branch: 1 branch
BranchTrueFalseTotal
if $to eq "hand" 3 259077 259080
78 259077 return ({ from => $from, to => $to }, undef);
79 }
80  
81 492716 ▶my $read = sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
82 492716 my ($move, $name) = @_;
83 492716 ▶ return $move->$name if Scalar::Util::blessed($move) && $move->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($move) and $move->can($name) 307671 185045 492716
Condition66%2/3
builtin::blessed($move) and $move->can($name)
!ll&&!rl&&r
1850450307671
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 185045 ▶ return ref $move eq 'HASH' ? $move->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $move eq 'HASH' ? : 185045 0 185045
85 83 };
86  
87 178854 ▶sub format_move {
Subroutine format_move: called CC=1 SCAR=0.0
Pod documented
88 178854 my ($move) = @_;
89 178854 return $read->($move, 'from') . '-' . $read->($move, 'to');
90 }
91  
92 45003 ▶sub format_display {
Subroutine format_display: called CC=4 SCAR=13.9
Pod documented
93 45003 my ($move, $roll) = @_;
94 45003 ▶ $roll = $read->($move, 'roll') unless defined $roll;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $roll 45002 1 45003
95 45003 ▶ return $roll . ': ' . format_move($move)
Branch: 2 branches
BranchTrueFalseTotal
&$read($move, 'captures') ? : 5717 39286 45003
&$read($move, 'rosette') ? : 9742 35261 45003
96 . ($read->($move, 'captures') ? 'x' : '')
97 . ($read->($move, 'rosette') ? '*' : '');
98 }
99  
100 11 ▶sub format_forfeit {
Subroutine format_forfeit: called CC=1 SCAR=0.0
Pod documented
101 11 my ($roll) = @_;
102 11 return $roll . ': -';
103 }
104  
105 752 ▶sub validate_position {
Subroutine validate_position: called CC=35 SCAR=35.6
Pod documented
106 752 my ($text) = @_;
107 752 ▶ return POS_NULL unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 2 750 752
Condition100%3/3
defined $text and length $text
!ll&&!rl&&r
11750
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 750 ▶ return POS_LONG if length $text >= 48;
Branch: 1 branch
BranchTrueFalseTotal
if length $text >= 48 1 749 750
109  
110 749 my @c = split //, $text;
111 749 my ($row, $file, $i) = (2, 0, 0);
112 749 ▶ 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 11618 5799 17417
Condition100%6/6
$row != 1 && ($file == 4 || $file == 5)
!ll&&!rl&&r
579987162902
$file == 4 or $file == 5
l!l&&r!l&&!r
145414488716
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 749 ▶ for (; $i < @c && $c[$i] ne ' '; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @c and $c[$i] ne " ") 15601 718 16319
Condition100%3/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
371515601
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 15601 my $ch = $c[$i];
116 15601 ▶ if ($ch eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "/") 1456 14145 15601
117 1456 ▶ return POS_WIDTH if $file != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file != 8 6 1450 1456
118 1450 ▶ return POS_ROWS if $row == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $row == 0 1 1449 1450
119 1449 $row--;
120 1449 $file = 0;
121 1449 next;
122 }
123 14145 ▶ if ($ch =~ /\A[1-8]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /\A[1-8]\z/) 3878 10267 14145
124 3878 for (1 .. $ch) {
125 7161 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 3 7158 7161
126 7158 ▶ return POS_GAP if $gap->();
Branch: 1 branch
BranchTrueFalseTotal
if &$gap() 6 7152 7158
127 7152 $file++;
128 }
129 3869 next;
130 }
131 10267 ▶ if ($ch eq 'x') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "x") 2899 7368 10267
132 2899 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 0 2899 2899
133 2899 ▶ return POS_X unless $gap->();
Branch: 1 branch
BranchTrueFalseTotal
unless &$gap() 5 2894 2899
134 2894 $file++;
135 2894 next;
136 }
137 7368 ▶ return POS_LETTER unless $ch eq 'l' || $ch eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
unless $ch eq "l" or $ch eq "d" 7 7361 7368
Condition100%3/3
$ch eq "l" or $ch eq "d"
l!l&&r!l&&!r
374136207
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 7361 ▶ return POS_WIDTH if $file >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file >= 8 1 7360 7361
139 7360 ▶ return POS_GAP if $gap->();
Branch: 1 branch
BranchTrueFalseTotal
if &$gap() 2 7358 7360
140 7358 $file++;
141 }
142 718 ▶ return POS_ROWS if $row != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $row != 0 5 713 718
143 713 ▶ return POS_WIDTH if $file != 8;
Branch: 1 branch
BranchTrueFalseTotal
if $file != 8 1 712 713
144  
145 712 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 1 711 712
Condition66%2/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
10711
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 711 $i++;
147 711 ▶ 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 706 711
Condition100%6/6
$i < @c and $c[$i] eq "l" || $c[$i] eq "d"
!ll&&!rl&&r
14706
$c[$i] eq "l" or $c[$i] eq "d"
l!l&&r!l&&!r
4412654
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 706 $i++;
149 706 for (1 .. 4) {
150 2795 ▶ return POS_FIELD unless $i < @c && $c[$i] eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
unless $i < @c and $c[$i] eq " " 5 2790 2795
Condition100%3/3
$i < @c and $c[$i] eq " "
!ll&&!rl&&r
322790
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 2790 $i++;
152 2790 ▶ return POS_FIELD if $i >= @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @c 2 2788 2790
153 2788 ▶ return POS_COUNT unless $c[$i] =~ /\A[0-7]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $c[$i] =~ /\A[0-7]\z/ 5 2783 2788
154 2783 $i++;
155 2783 ▶ return POS_COUNT if $i < @c && $c[$i] ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c and $c[$i] ne " " 4 2779 2783
Condition100%3/3
$i < @c and $c[$i] ne " "
!ll&&!rl&&r
69020894
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 690 ▶ return POS_FIELD if $i < @c;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @c 2 688 690
158 688 return POS_OK;
159 }
160  
161 1876 ▶my $rules_text = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
162 1876 my ($rules) = @_;
163 1876 ▶ return $rules unless ref $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rules 1858 18 1876
164 18 return join ' ', map { "$_=$rules->{$_}" } @FIELDS;
165 83 };
166  
167 681 ▶my $rules_of = sub {
Subroutine __ANON__: called CC=10 SCAR=23.3
168 681 my ($text) = @_;
169 681 ▶ return $text if exists $NAMED{$text};
Branch: 1 branch
BranchTrueFalseTotal
if exists $NAMED{$text} 666 15 681
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 83 };
182  
183 678 ▶my $spelled = sub { ref $_[0] ? $_[0] : $NAMED{ $_[0] } };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 12 666 678
184  
185 1876 ▶sub format_record {
Subroutine format_record: called CC=9 SCAR=22.0
Pod documented
186 1876 my ($record) = @_;
187 my @lines = (
188 '[rules ' . $rules_text->($record->{rules}) . ']',
189 1876 '[first ' . $record->{first} . ']',
190 );
191 1876 ▶ push @lines, '[position ' . $record->{position} . ']' if defined $record->{position};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"position"} 64 1812 1876
192 1876 ▶ push @lines, '[seed ' . $record->{seed} . ']' if defined $record->{seed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $record->{"seed"} 1820 56 1876
193 1876 ▶ push @lines, '[opening ' . $record->{opening} . ']' if $record->{opening};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"opening"} 775 1101 1876
194 1876 my $n = 0;
195 1876 ▶ for my $turn (@{ $record->{turns} || [] }) {
Condition50%1/2
$record->{'turns'} || []
l!l
18760
MC/DC0%0/1
$record->{'turns'} || []
$record->{'turns'}
Truth table50%1/2
A
A= $record->{'turns'}
Aresult
11
00
196 204234 $n++;
197 push @lines, $n . '. ' . $LETTER_OF{ $turn->{side} } . ' ' . $turn->{roll}
198 . (defined $turn->{faces} ? ' ' . $turn->{faces} : '')
199 204234 ▶ . ': ' . (defined $turn->{move} ? $turn->{move} : '-');
Branch: 2 branches
BranchTrueFalseTotal
defined $turn->{'faces'} ? : 204198 36 204234
defined $turn->{'move'} ? : 195737 8497 204234
200 }
201 push @lines, '[result ' . $record->{result}{winner} . ' ' . $record->{result}{how} . ']'
202 1876 ▶ if $record->{result};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"result"} 908 968 1876
203 1876 return join("\n", @lines) . "\n";
204 }
205  
206 729 ▶sub parse_record {
Subroutine parse_record: called CC=37 SCAR=36.1
Pod documented
207 729 my ($text) = @_;
208 729 ▶ my $fail = sub { return (undef, { line => $_[0], error => $_[1] }) };
Subroutine __ANON__: called CC=1 SCAR=0.0
209 729 ▶ return $fail->(0, 'empty') unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 2 727 729
Condition66%2/3
defined $text and length $text
!ll&&!rl&&r
02727
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
210 727 ▶ return $fail->(0, 'no_newline') unless $text =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\n\z/ 2 725 727
211  
212 725 my @lines = split /\n/, $text, -1;
213 725 pop @lines;
214 725 my %record = (turns => []);
215 725 my ($at, $expect, $done) = (0, undef, 0);
216  
217 3429 ▶ my $header = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
218 3429 my ($name, $pattern) = @_;
219 3429 ▶ 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/ 1107 2322 3429
Condition100%3/3
$at < @lines and $lines[$at] =~ /\A\[\Q$name\E ($pattern)\]\z/
!ll&&!rl&&r
1410932322
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 2322 $at++;
221 2322 return $1;
222 725 };
223  
224 725 my $rules = $header->('rules', '[a-z0-9_= ]+');
225 725 ▶ return $fail->($at + 1, 'rules') unless defined $rules;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rules 44 681 725
226 681 $record{rules} = $rules_of->($rules);
227 681 ▶ return $fail->($at, 'rules') unless defined $record{rules};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"rules"} 3 678 681
228 678 my $set = $spelled->($record{rules});
229  
230 678 $record{first} = $header->('first', 'light|dark');
231 678 ▶ return $fail->($at + 1, 'first') unless defined $record{first};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record{"first"} 2 676 678
232  
233 676 my $position = $header->('position', '[0-9xld/ ]+');
234 676 ▶ return $fail->($at, 'position') if defined $position && validate_position($position);
Branch: 1 branch
BranchTrueFalseTotal
if defined $position and validate_position($position) 1 675 676
Condition100%3/3
defined $position and validate_position($position)
!ll&&!rl&&r
662131
MC/DC100%2/2
defined $position and validate_position($position)
defined $position validate_position($position)
Truth table100%3/3
A and B
A= defined $positionB= validate_position($position)
ABresult
0X0
100
111
235 675 ▶ $record{position} = $position if defined $position;
Branch: 1 branch
BranchTrueFalseTotal
if defined $position 13 662 675
236  
237 675 my $seed = $header->('seed', '(?:[0-9a-f]{2})+');
238 675 ▶ $record{seed} = $seed if defined $seed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seed 642 33 675
239 675 my $opening = $header->('opening', '[1-9][0-9]*');
240 675 ▶ $record{opening} = $opening + 0 if defined $opening;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opening 309 366 675
241 675 ▶ return $fail->($at, 'opening') if defined $opening && ($opening % 2 || !defined $seed);
Branch: 1 branch
BranchTrueFalseTotal
if defined $opening and $opening % 2 || !defined($seed) 2 673 675
Condition100%6/6
defined $opening and $opening % 2 || !defined($seed)
!ll&&!rl&&r
3663072
$opening % 2 or not defined $seed
l!l&&r!l&&!r
11307
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
242  
243 673 ▶ my $bytes = defined $seed ? pack('H*', $seed) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $seed ? : 641 32 673
244 673 ▶ my $throw = $record{opening} || 0;
Condition100%2/2
$record{'opening'} || 0
l!l
307366
MC/DC100%1/1
$record{'opening'} || 0
$record{'opening'}
Truth table100%2/2
A
A= $record{'opening'}
Aresult
11
00
245 673 $expect = $record{first};
246  
247 673 ▶ for (; $at < @lines; $at++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at < @lines) 94329 648 94977
248 94329 my $line = $lines[$at];
249 94329 my $number = $at + 1;
250 94329 ▶ return $fail->($number, 'after_result') if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 1 94328 94329
251  
252 94328 ▶ if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\A\[result ([a-z_]+ [a-z_]+)\]\z/) 495 93833 94328
253 495 ▶ return $fail->($number, 'result') unless $RESULT_OK{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless $RESULT_OK{$1} 2 493 495
254 493 my ($winner, $how) = split / /, $1;
255 493 $record{result} = { winner => $winner, how => $how };
256 493 $done = 1;
257 493 next;
258 }
259  
260 93833 ▶ 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") 93830 3 93833
261 $line =~ /\A([1-9][0-9]*)\. ([ld]) ([0-4])(?: ([01]{3,4}))?: (\S+)\z/
262 or return $fail->($number, 'turn');
263 93830 ▶ return $fail->($number, 'number') unless $n == @{ $record{turns} } + 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $n == @{$record{"turns"};} + 1 2 93828 93830
264  
265 93828 my $side = $SIDE_OF{$letter};
266 93828 ▶ return $fail->($number, 'side') unless $side eq $expect;
Branch: 1 branch
BranchTrueFalseTotal
unless $side eq $expect 7 93821 93828
267  
268 93821 ▶ if (defined $faces) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $faces) 93765 56 93821
269 93765 ▶ return $fail->($number, 'faces') unless length $faces == $set->{dice};
Branch: 1 branch
BranchTrueFalseTotal
unless length $faces == $set->{"dice"} 1 93764 93765
270 93764 my $marked = ($faces =~ tr/1//);
271 93764 ▶ return $fail->($number, 'faces')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::RoyalUr::Dice::roll_of($marked, $set) == $roll 2 93762 93764
272 unless Game::RoyalUr::Dice::roll_of($marked, $set) == $roll;
273 }
274 93818 ▶ if (defined $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bytes) 93726 92 93818
275 93726 my $thrown = Game::RoyalUr::Dice::throw_for($bytes, $throw, $set->{dice});
276 93726 ▶ return $fail->($number, 'roll')
Branch: 1 branch
BranchTrueFalseTotal
unless Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($thrown), $set) == $roll 3 93723 93726
277 unless Game::RoyalUr::Dice::roll_of(Game::RoyalUr::Dice::marked($thrown), $set) == $roll;
278 93723 ▶ return $fail->($number, 'faces') if defined $faces && $faces ne join('', @$thrown);
Branch: 1 branch
BranchTrueFalseTotal
if defined $faces and $faces ne join("", @$thrown) 1 93722 93723
Condition100%3/3
defined $faces and $faces ne join("", @$thrown)
!ll&&!rl&&r
16937061
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
279 }
280 93814 $throw++;
281  
282 93814 my %turn = (side => $side, roll => $roll + 0);
283 93814 ▶ $turn{faces} = $faces if defined $faces;
Branch: 1 branch
BranchTrueFalseTotal
if defined $faces 93760 54 93814
284 93814 ▶ my $other = $side eq 'light' ? 'dark' : 'light';
Branch: 1 branch
BranchTrueFalseTotal
$side eq 'light' ? : 46973 46841 93814
285 93814 ▶ if ($move eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($move eq '-') { } 3761 90053 93814
286 3761 $turn{move} = undef;
287 3761 $expect = $other;
288 }
289 else {
290 90053 my ($parsed, $error) = parse_move($move);
291 90053 ▶ return $fail->($number, 'move') unless $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed 2 90051 90053
292 90051 ▶ return $fail->($number, 'move') unless $move eq format_move($parsed);
Branch: 1 branch
BranchTrueFalseTotal
unless $move eq format_move($parsed) 1 90050 90051
293 90050 $turn{move} = $move;
294 90050 ▶ $expect = $ROSETTE{ $parsed->{to} } ? $side : $other;
Branch: 1 branch
BranchTrueFalseTotal
$ROSETTE{$parsed->{'to'}} ? : 19041 71009 90050
295 }
296 93811 push @{ $record{turns} }, \%turn;
297 }
298 648 return (\%record, undef);
299 }
300  
301 83 1;
302  
303 __END__
↑ Summary blib/lib/Game/RoyalUr/Terminal.pm »