script_files/pairtable2yaml

filter: Statementstmt 100% 44 / 44 Branchbran 83.3% 15 / 18 Conditioncond 66.6% 14 / 21 MC/DCmcdc 50.0% 7 / 14 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 83.5% 86 / 103 CC 1 SCAR 0.0
CC
1
Cov
88%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« script_files/pair ↑ Summary blib/lib/Games/Tournament/Swiss/Procedure.pm »
1 #!/usr/bin/perl
2  
3 =head1 NAME
4  
5 pairtable2yaml - Create YAML version of pairing table
6  
7 =cut
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use YAML qw/LoadFile DumpFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 our $RD_HINT=1;
17 1 ▶use List::MoreUtils qw/firstval/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 my $io = io $ARGV[0];
20 1 my @lines = $io->slurp;
21  
22 # shift @lines; shift @lines; shift @lines; shift @lines;
23 1 my $table;
24  
25 1 for my $line ( @lines )
26 {
27 7 our ($player, $opponents, $roles, $b5float, $b6float, $score, $result);
28 7 my $format = q{
29 line: data end | longform end | comment end | <error>
30 data: player opponents roles floats score
31 longform: place player opponents roles floats score
32 place: wholenumber(s /-/)
33 player: id { $::player = $item[1] }
34 id: wholenumber
35 wholenumber: m/^\d+/
36 Bye: '-'
37 opponents: opponent(s /,/) { $::opponents = $item[1] }
38 opponent: id | Bye
39 roles: role(s) { $::roles = $item[1] }
40 role: White | Black | Bye
41 White: 'W'
42 Black: 'B'
43 floats: B6andB5 | B5andB6 | B5float | B6float | NotFloat
44 B6andB5: B6float B5float
45 {
46 $::b5float ||= $item{'B5float'};
47 $::b6float ||= $item{'B6float'};
48 }
49 B5andB6: B5float B6float
50 {
51 $::b5float ||= $item{'B5float'};
52 $::b6float ||= $item{'B6float'};
53 }
54 B6float: lowercasefloat
55 {
56 $::b6float ||= $item{'lowercasefloat'};
57 }
58 lowercasefloat: 'u' | 'd'
59 B5float: uppercasefloat
60 {
61 $::b5float ||= $item{'uppercasefloat'};
62 }
63 uppercasefloat: 'U' | 'D'
64 NotFloat: ''
65 score: scorenumber { $::score = $item[1] }
66 scorenumber: m/^\d+(?:\.5)?/
67 comment: token(s?) {$::result = 'comment'}
68 token: m/\S+/
69 end: m/^\Z/
70 };
71  
72 7 my $parser = Parse::RecDescent->new($format);
73 7 ▶ defined $parser->line($line) or die "parser died: $?\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $parser->line($line) or die "parser died: $?\n" 7 0 7
74 7 ▶ unless ( $result and $result eq 'comment' )
Branch: 1 branch
BranchTrueFalseTotal
unless ($main::result and $main::result eq "comment") 4 3 7
Condition66%2/3
$main::result and $main::result eq "comment"
!ll&&!rl&&r
403
MC/DC50%1/2
$main::result and $main::result eq "comment"
$main::result $main::result eq "comment"
Truth table66%2/3
A and B
A= $main::resultB= $main::result eq "comment"
ABresult
0X0
100
111
75 {
76 4 for ( @$opponents )
77 {
78 16 ▶ $_ = 'Bye' if $_ and $_ eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $_ eq "-" 0 16 16
Condition33%1/3
$_ and $_ eq "-"
!ll&&!rl&&r
0160
MC/DC0%0/2
$_ and $_ eq "-"
$_ $_ eq "-"
Truth table33%1/3
A and B
A= $_B= $_ eq "-"
ABresult
0X0
100
111
79 }
80 4 $table->{opponents}->{$player} = $opponents;
81 4 for ( @$roles )
82 {
83 16 ▶ $_ = 'White' if $_ and $_ eq 'W';
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $_ eq "W" 8 8 16
Condition66%2/3
$_ and $_ eq "W"
!ll&&!rl&&r
088
MC/DC50%1/2
$_ and $_ eq "W"
$_ $_ eq "W"
Truth table66%2/3
A and B
A= $_B= $_ eq "W"
ABresult
0X0
100
111
84 16 ▶ $_ = 'Black' if $_ and $_ eq 'B';
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $_ eq "B" 8 8 16
Condition66%2/3
$_ and $_ eq "B"
!ll&&!rl&&r
088
MC/DC50%1/2
$_ and $_ eq "B"
$_ $_ eq "B"
Truth table66%2/3
A and B
A= $_B= $_ eq "B"
ABresult
0X0
100
111
85 16 ▶ $_ = 'Bye' if $_ and $_ eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $_ eq "-" 0 16 16
Condition33%1/3
$_ and $_ eq "-"
!ll&&!rl&&r
0160
MC/DC0%0/2
$_ and $_ eq "-"
$_ $_ eq "-"
Truth table33%1/3
A and B
A= $_B= $_ eq "-"
ABresult
0X0
100
111
86 }
87 4 $table->{roles}->{$player} = $roles;
88 4 for ( $b5float, $b6float )
89 {
90 8 ▶ $_ = 'Up' if $_ and $_ =~ m/^U$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $_ =~ /^U$/i 1 7 8
Condition100%3/3
$_ and $_ =~ /^U$/i
!ll&&!rl&&r
431
MC/DC100%2/2
$_ and $_ =~ /^U$/i
$_ $_ =~ /^U$/i
Truth table100%3/3
A and B
A= $_B= $_ =~ /^U$/i
ABresult
0X0
100
111
91 8 ▶ $_ = 'Down' if $_ and $_ =~ m/^D$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $_ and $_ =~ /^D$/i 3 5 8
Condition100%3/3
$_ and $_ =~ /^D$/i
!ll&&!rl&&r
413
MC/DC100%2/2
$_ and $_ =~ /^D$/i
$_ $_ =~ /^D$/i
Truth table100%3/3
A and B
A= $_B= $_ =~ /^D$/i
ABresult
0X0
100
111
92 8 ▶ $_ = undef unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 4 4 8
93 }
94 4 $table->{floats}->{$player} = [ $b6float, $b5float ];
95 4 $table->{score}->{$player} = $score;
96 }
97 7 ($::player, $::opponents, $::roles, $::b5float, $::b6float, $::score, $::result) = undef;
98 }
99  
100 1 DumpFile 'pairtable.yaml', $table;
101  
102 __END__
« script_files/pair ↑ Summary blib/lib/Games/Tournament/Swiss/Procedure.pm »