| 1 | package WWW::CBF; | ||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use utf8::all; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Web::Scraper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 0 | ▶ | eval 'use HTML::TreeBuilder::LibXML'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | our $VERSION = '0.03'; | |||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | my $cbf = scraper { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 13 | 0 | ▶ | process 'tr', 'clubes[]' => scraper { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 14 | 0 | process 'td', 'dados[]' => 'TEXT'; | |||||||||
| 15 | }, | ||||||||||
| 16 | 0 | }; | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 0 | my $class = shift; | |||||||||
| 20 | 0 | my $self = {}; | |||||||||
| 21 | 0 | bless $self, $class; | |||||||||
| 22 | |||||||||||
| 23 | 0 | $self->reload; | |||||||||
| 24 | 0 | return $self; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | sub reload { | ||||||||
|
Subroutine
reload: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 28 | 0 | 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}} ) { | |||||||||
| 35 | 0 | ▶ | next if ++$pos == 0; # first entry contains just table fields | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | |||||||||||
| 37 | # get values from scraper | ||||||||||
| 38 | $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 | 0 | ap => $clube->{dados}->[11], | |||||||||
| 49 | }; | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | return $self; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub pos { | ||||||||
|
Subroutine
pos: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | 0 | my $self = shift; | |||||||||
| 58 | 0 | my $pos = shift; | |||||||||
| 59 | |||||||||||
| 60 | 0 | return $self->{$pos}; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 3 | 42; | |||||||||
| 64 | __END__ | ||||||||||