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

filter: Statementstmt 41.9% 26 / 62 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 53.3% 8 / 15 Podpod 100% 2 / 2 totaltotal 37.5% 36 / 96 CC 11 SCAR 35.2
CC
11
Cov
33%
scrape
90.0
__ANON__
3.7
__ANON__
3.7
CRAP 33.6
« blib/lib/WWW/GoKGS/Scraper/GameArchives.pm ↑ Summary blib/lib/WWW/GoKGS/Scraper/Filters.pm »
1 package WWW::GoKGS::Scraper::TournGames;
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 game_result/;
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/tournGames.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=3.8
12 1 my $self = shift;
13 1 my $links = $self->__build_tourn_links;
14  
15 my %h1 = (
16 0 ▶ name => [ 'TEXT', sub { s/ Round \d+ Games$// } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 ▶ round => [ 'TEXT', sub { m/ Round (\d+) Games$/ && $1 } ],
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
/ Round (\d+) Games$/ and $1 0 0 0
18 );
19  
20 my %player = (
21 0 ▶ name => [ 'TEXT', sub { s/ \[[^\]]+\]$// } ],
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ rank => [ 'TEXT', sub { m/ \[([^\]]+)\]$/ && $1 } ],
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
/ \[([^\]]+)\]$/ and $1 0 0 0
23 );
24  
25 0 ▶ my $game = scraper {
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 process '//td[1]/a', 'sgf_uri' => '@href';
27 0 process '//td[2]', 'white' => \%player;
28 0 process '//td[3]', 'black' => \%player,
29 'maybe_bye' => 'TEXT';
30 0 process '//td[4]', 'setup' => 'TEXT';
31 0 process '//td[5]', 'start_time' => [ 'TEXT', \&datetime ];
32 0 process '//td[6]', 'result' => [ 'TEXT', \&game_result ];
33 1 };
34  
35 0 ▶ scraper {
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 process '//h1', %h1;
37 0 process '//a[@href="tzList.jsp"]', 'time_zone' => 'TEXT';
38 0 process '//table[@class="grid"]//following-sibling::tr',
39 'games[]' => $game;
40 0 process '//a[text()="Previous round"]', 'previous_round_uri' => '@href';
41 0 process '//a[text()="Next round"]', 'next_round_uri' => '@href';
42 0 process '//div[@class="tournData"]', 'links' => $links;
43 1 };
44 }
45  
46 0 ▶sub scrape {
Subroutine scrape: not called CC=9 SCAR=45.0
Pod documented
47 0 my ( $self, @args ) = @_;
48 0 my $result = $self->SUPER::scrape( @args );
49  
50 0 ▶ return $result unless $result->{games};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->{"games"} 0 0 0
51  
52 0 my ( @games, @byes );
53 0 for my $game ( @{$result->{games}} ) {
54 0 my $maybe_bye = delete $game->{maybe_bye};
55 0 ▶ if ( $maybe_bye =~ /^Bye(?: \(([^\)]+)\))?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_bye =~ /^Bye(?: \(([^\)]+)\))?$/) { } 0 0 0
56 push @byes, {
57 type => $1 || 'System',
58 0 ▶ %{$game->{white}},
Condition0%0/2
$1 || 'System'
l!l
00
MC/DC0%0/1
$1 || 'System'
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
59 };
60 }
61 else {
62 0 push @games, $game;
63 }
64 }
65  
66 0 for my $game ( @games ) {
67 0 $game->{setup} =~ /^(\d+)\x{d7}\d+ (?:H(\d+))?$/;
68 0 $game->{board_size} = $1;
69 0 ▶ $game->{handicap} = $2 if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 0 0 0
70  
71 0 delete $game->{setup};
72 }
73  
74 0 delete $result->{games};
75  
76 0 ▶ $result->{byes} = \@byes if @byes;
Branch: 1 branch
BranchTrueFalseTotal
if @byes 0 0 0
77 0 ▶ $result->{games} = \@games if @games;
Branch: 1 branch
BranchTrueFalseTotal
if @games 0 0 0
78  
79 0 $result;
80 }
81  
82 15 1;
83  
84 __END__
« blib/lib/WWW/GoKGS/Scraper/GameArchives.pm ↑ Summary blib/lib/WWW/GoKGS/Scraper/Filters.pm »