NPB.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 3 totaltotal 88.8% 56 / 63 CC 5 SCAR 5.5
CC
5
Cov
94%
_parse_body
3.0
croak
2.0
games
2.0
CRAP 1.7
↑ Summary NPB/Game.pm »
1 package WWW::Baseball::NPB;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 $VERSION = 0.03;
6  
7 4 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use WWW::Baseball::NPB::Game;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use vars qw($YahooURL);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 $YahooURL = 'http://sports.yahoo.co.jp/baseball/';
12  
13 0 ▶sub croak { require Carp; Carp::croak(@_) }
Subroutine croak: not called CC=1 SCAR=6.9
Pod undocumented
14  
15 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
16 3 my $class = shift;
17 3 my $self = bless { games => [] }, $class;
18 3 $self->_parse_body($YahooURL);
19 3 return $self;
20 }
21  
22 4 ▶sub games {
Subroutine games: called CC=2 SCAR=6.9
Pod undocumented
23 4 my($self, $league) = @_;
24 4 ▶ unless ($league) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($league) 3 1 4
25 3 return @{$self->{games}};
26 }
27 1 return grep { $_->league eq $league } @{$self->{games}};
28 }
29  
30 3 ▶sub _parse_body {
Subroutine _parse_body: called CC=3 SCAR=11.0
31 3 my($self, $url) = @_;
32 3 ▶ my $body = LWP::Simple::get($url) or croak("Can't get content of $url");
Branch: 1 branch
BranchTrueFalseTotal
my $body = &LWP::Simple::get($url) or croak("Can't get content of $url") 3 0 3
33 3 my $re = $self->_match_pattern;
34 3 ▶ while ($body =~ m/$re/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ /$re/g) 18 3 21
35 18 $self->_add_game($1, $2, $3, $4, $5, $6, $7);
36 }
37 }
38  
39 4 my %league = (cl => 'central', pl => 'pacific');
40  
41 18 ▶sub _add_game {
Subroutine _add_game: called CC=2 SCAR=6.9
42 18 my($self, $home, $home_score, $visitor_score, $league, $status, $visitor, $stadium) = @_;
43 18 for ($home_score, $visitor_score) {
44 36 s,<b>(.*)</b>,$1,;
45 }
46 18 push @{$self->{games}}, WWW::Baseball::NPB::Game->new(
47 home => $home,
48 visitor => $visitor,
49 score => {
50 $home => $home_score,
51 $visitor => $visitor_score,
52 },
53 18 league => $league{$league},
54 status => $status,
55 stadium => $stadium,
56 );
57 }
58  
59 3 ▶sub _match_pattern {
Subroutine _match_pattern: called CC=1 SCAR=0.0
60 3 return <<'RE';
61 <tr valign="top">
62 <td align="right" width=35%>
63 <b><a href=".*?">(.*?)</a>
64 </b>
65 </td>
66 <td align="center" width=30%>(\S*) ?- ?(\S*)<br><a href="/baseball/(cl|pl)/scores/.*?">(.*?)</a>
67 </td>
68 <td align="left" width=35%><b><a href=".*?">(.*?)</a>
69 </b>
70 (?:</td>\n)?</tr>
71 <tr>(?:<td colspan=3 align=center><small>\[ <a href=".*?">¥é¥¤¥Ö</a> \]</small></td></tr><tr>)?
72 <td align="center" colspan=3 ?>(.*?)</td>
73 </tr>
74 <tr><td height=4 colspan=3></td></tr>
75 RE
76 ;
77 }
78  
79 4 1;
80 __END__
↑ Summary NPB/Game.pm »