blib/lib/WWW/GoKGS/Scraper/TournEntrants.pm

filter: Statementstmt 26.9% 24 / 89 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 8 / 16 Podpod 100% 2 / 2 totaltotal 24.8% 34 / 137 CC 21 SCAR 54.6
CC
21
Cov
21%
scrape
420.0
__ANON__
3.7
__ANON__
2.0
CRAP 234.1
↑ Summary blib/lib/WWW/GoKGS/Scraper/GameArchives.pm »
1 package WWW::GoKGS::Scraper::TournEntrants;
2 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use parent qw/WWW::GoKGS::Scraper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use WWW::GoKGS::Scraper::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use WWW::GoKGS::Scraper::Filters qw/datetime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use WWW::GoKGS::Scraper::TournLinks;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 ▶sub base_uri { 'http://www.gokgs.com/tournEntrants.jsp' }
Subroutine base_uri: called CC=1 SCAR=0.0
Pod documented
10  
11 1 ▶sub __build_scraper {
Subroutine __build_scraper: called CC=1 SCAR=4.7
12 1 my $self = shift;
13 1 my $links = $self->__build_tourn_links;
14  
15 my %user = (
16 0 ▶ name => [ 'TEXT', sub { s/ \[[^\]]+\]$// } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 ▶ rank => [ 'TEXT', sub { m/ \[([^\]]+)\]$/ && $1 } ],
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
/ \[([^\]]+)\]$/ and $1 0 0 0
18 );
19  
20 0 ▶ scraper {
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 ▶ process '//h1', 'name' => [ 'TEXT', sub { s/ Players$// } ];
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 process '//a[@href="tzList.jsp"]', 'time_zone' => 'TEXT';
23 process '//table[tr/th[3]/text()="Score"]//following-sibling::tr',
24 0 ▶ 'entrants[]' => scraper { # Swiss or McMahon
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 process '//td[1]', 'position' => 'TEXT';
26 0 process '//td[2]', %user;
27 0 process '//td[3]', 'score' => 'TEXT';
28 0 process '//td[4]', 'sos' => 'TEXT';
29 0 process '//td[5]', 'sodos' => 'TEXT';
30 0 process '//td[6]', 'notes' => 'TEXT'; };
31 process '//table[tr/th[1]/text()="Name"]//following-sibling::tr',
32 0 ▶ 'entrants[]' => scraper { # Single or Double Elimination
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 process '//td[1]', %user;
34 0 process '//td[2]', 'standing' => 'TEXT'; };
35 process '//table[tr/th[3]/text()="#"]//following-sibling::tr',
36 0 ▶ 'entrants[]' => scraper { # Round Robin
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 process '//td', 'columns[]' => 'TEXT';
38 0 result 'columns'; };
39 0 process '//div[@class="tournData"]', 'links' => $links;
40 1 };
41 }
42  
43 0 ▶sub scrape {
Subroutine scrape: not called CC=20 SCAR=60.4
Pod documented
44 0 my ( $self, @args ) = @_;
45 0 my $result = $self->SUPER::scrape( @args );
46  
47 0 ▶ return $result unless $result->{entrants};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->{"entrants"} 0 0 0
48  
49 0 ▶ if ( !$result->{entrants}->[0] ) { # Round Robin
Branch: 2 branches
BranchTrueFalseTotal
if (not $result->{'entrants'}[0]) { } 0 0 0
elsif (exists $result->{'entrants'}[0]{'score'}) { } 0 0 0
50 0 shift @{$result->{entrants}};
51  
52 0 my @entrants;
53 0 my $size = @{$result->{entrants}->[0]};
54 0 for my $entrant ( @{$result->{entrants}} ) {
55 0 $entrant->[0] =~ s/\(tie\)$//;
56  
57 push @entrants, {
58 position => @$entrant == $size ? int shift @$entrant : $entrants[-1]{position},
59 0 ▶ name => shift @$entrant,
Branch: 1 branch
BranchTrueFalseTotal
@$entrant == $size ? : 0 0 0
60 number => shift @$entrant,
61 notes => pop @$entrant,
62 score => pop @$entrant,
63 results => $entrant,
64 };
65 }
66  
67 0 for my $entrant ( @entrants ) {
68 0 $entrant->{name} =~ /^([a-zA-Z0-9]+)(?: \[([^\]]+)\])?$/;
69 0 $entrant->{name} = $1;
70 0 $entrant->{rank} = $2;
71 }
72  
73 0 my %results;
74 0 for my $a ( @entrants ) {
75 0 ▶ next unless $a->{number};
Branch: 1 branch
BranchTrueFalseTotal
unless $a->{"number"} 0 0 0
76 0 for my $b ( @entrants ) {
77 0 ▶ next if $b == $a;
Branch: 1 branch
BranchTrueFalseTotal
if $b == $a 0 0 0
78 0 ▶ next unless $b->{number};
Branch: 1 branch
BranchTrueFalseTotal
unless $b->{"number"} 0 0 0
79 $results{$a->{name}}{$b->{name}}
80 0 ▶ = $a->{results}->[$b->{number}-1] || q{};
Condition0%0/2
$a->{'results'}[$b->{'number'} - 1] || ''
l!l
00
MC/DC0%0/1
$a->{'results'}[$b->{'number'} - 1] || ''
$a->{'results'}[$b->{'number'} - 1]
Truth table0%0/2
A
A= $a->{'results'}[$b->{'number'} - 1]
Aresult
11
00
81 }
82 }
83  
84 0 delete @{$_}{qw/number results/} for @entrants;
85  
86 0 $result->{entrants} = \@entrants;
87 0 ▶ $result->{results} = \%results if %results;
Branch: 1 branch
BranchTrueFalseTotal
if %results 0 0 0
88 }
89 elsif ( exists $result->{entrants}->[0]->{score} ) { # Swiss or McMahon
90 0 my $preceding;
91 0 for my $entrant ( @{$result->{entrants}} ) {
92 0 $entrant->{position} =~ s/\(tie\)$//;
93 0 ▶ next if !$preceding or exists $entrant->{notes};
Branch: 1 branch
BranchTrueFalseTotal
if not $preceding or exists $entrant->{"notes"} 0 0 0
Condition0%0/3
not $preceding or exists $entrant->{"notes"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $preceding or exists $entrant->{"notes"}
not $preceding exists $entrant->{"notes"}
Truth table0%0/3
not(A) or B
A= not $precedingB= exists $entrant->{"notes"}
ABresult
1X1
011
000
94 0 $entrant->{notes} = $entrant->{sodos};
95 0 $entrant->{sodos} = $entrant->{sos};
96 0 $entrant->{sos} = $entrant->{score};
97 0 $entrant->{score} = $entrant->{name};
98 0 $entrant->{position} =~ /^([a-zA-Z0-9]+)(?: \[([^\]]+)\])?$/;
99 0 $entrant->{name} = $1;
100 0 $entrant->{rank} = $2;
101 0 $entrant->{position} = $preceding->{position};
102 }
103 continue {
104 0 $preceding = $entrant;
105 }
106 }
107 else { # Single or Double Elimination
108 }
109  
110 0 for my $entrant ( @{$result->{entrants}} ) {
111 0 ▶ delete $entrant->{rank} unless $entrant->{rank};
Branch: 1 branch
BranchTrueFalseTotal
unless $entrant->{"rank"} 0 0 0
112 }
113  
114 0 $result;
115 }
116  
117 15 1;
118  
119 __END__
↑ Summary blib/lib/WWW/GoKGS/Scraper/GameArchives.pm »