1 package Data::StarCraft::PvPGN::Report;
12 open my $file, '<', $path or carp("No report file: $!\n"), return undef;
13 bless $file, $package;
19 while (defined ($_ = readline $file)) {
20 # empty line = end of head
22 # strip first key=val pair
24 ^\s* ([a-zA-Z]+) = ("(?: [^"\\] | \\. )*" | \S*)
25 }{}x or chomp, warn("Unknown pvpgn report header line: $_\n"), next;
26 my ($key, $val) = ($1, $2);
27 $val =~ s/^"(.*)"$/$1/ and $val =~ s/\\(.)/$1/g; # unquote
29 redo if /\S/; # other pairs on this line
38 while (defined ($_ = readline $file)) {
39 # ignore leading empty lines; stop if trailing
40 /\S/ or @player ? last : next;
41 my ($name, $result, $ladder) = /^ (\S+) \s+ ([A-Z]+) \s* (.*)/x
42 or chomp, warn("Unknown pvpgn report player line: $_\n");
43 push @player, {name => $name, result => $result};
45 my @ladderdata = $ladder =~ m{
46 ^ \s* rating=(\d+) \s+ \[\#\d+\]
47 \s+ prob=([\d.]+)% \s+ K=(\d+) \s+ adj=([+-]\d+) \s* $
48 }x ? $player[-1]{ladder} = {
53 } : warn("Unknown ladder details for player $name: $ladder\n");
58 while (defined ($_ = readline $file)) {
59 m{<race>([^<]+)</race>} or next;
62 or die("More <race> entries than $i found players\n");
63 last unless $player[$i]->{result} eq "DISCONNECT";
65 $player[$i]->{race}= $1;