File Coverage

blib/lib/WWW/CBF.pm
Criterion Covered Total %
statement 16 35 45.7
branch 0 2 0.0
condition n/a
subroutine 6 9 66.6
pod 3 3 100.0
total 25 49 51.0


line stmt bran cond sub pod time code
1             package WWW::CBF;
2 2     2   49519 use warnings;
  2         5  
  2         63  
3 2     2   12 use strict;
  2         2  
  2         61  
4              
5 2     2   2053 use utf8::all;
  2         168298  
  2         18  
6 2     2   11961 use URI;
  2         18598  
  2         84  
7 2     2   2652 use Web::Scraper;
  2         186850  
  2         16  
8 2     2   756 eval 'use HTML::TreeBuilder::LibXML';
  0            
  0            
9              
10             our $VERSION = '0.03';
11              
12             my $cbf = scraper {
13             process 'tr', 'clubes[]' => scraper {
14             process 'td', 'dados[]' => 'TEXT';
15             },
16             };
17              
18             sub new {
19 0     0 1   my $class = shift;
20 0           my $self = {};
21 0           bless $self, $class;
22              
23 0           $self->reload;
24 0           return $self;
25             }
26              
27             sub reload {
28 0     0 1   my $self = shift;
29 0           my $url = 'http://www.cbf.com.br/competicoes/campeonato-brasileiro/serie-a/2012';
30              
31 0           my $site = $cbf->scrape( URI->new($url) );
32              
33 0           my $pos = -1;
34 0           foreach my $clube ( @{$site->{clubes}} ) {
  0            
35 0 0         next if ++$pos == 0; # first entry contains just table fields
36              
37             # get values from scraper
38 0           $self->{$pos} = {
39             clube => $clube->{dados}->[1],
40             pontos => $clube->{dados}->[3],
41             jogos => $clube->{dados}->[4],
42             vitorias => $clube->{dados}->[5],
43             empates => $clube->{dados}->[6],
44             derrotas => $clube->{dados}->[7],
45             gp => $clube->{dados}->[8],
46             gc => $clube->{dados}->[9],
47             sg => $clube->{dados}->[10],
48             ap => $clube->{dados}->[11],
49             };
50             }
51              
52 0           return $self;
53             }
54              
55              
56             sub pos {
57 0     0 1   my $self = shift;
58 0           my $pos = shift;
59              
60 0           return $self->{$pos};
61             }
62              
63             42;
64             __END__