blib/lib/WWW/Scraper/ISBN/Siciliano_Driver.pm

filter: Statementstmt 77.6% 52 / 67 Branchbran 25.0% 3 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 69.4% 66 / 95 CC 8 SCAR 21.1
CC
8
Cov
67%
search
16.5
BEGIN
1.0
BEGIN
1.0
CRAP 8.3
↑ Summary
1 package WWW::Scraper::ISBN::Siciliano_Driver;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.02';
7  
8 2 ▶use base qw( WWW::Scraper::ISBN::Driver );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use LWP::Simple qw(head);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use constant SICILIANO => 'http://www.siciliano.com.br';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use constant SEARCHBR => 'http://www.siciliano.com.br/livro.asp?tipo=10&pesquisa=5&id=';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use constant SEARCH => 'http://www.siciliano.com.br/importado.asp?tipo=10&pesquisa=5&id=';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 1 ▶sub search {
Subroutine search: called CC=8 SCAR=28.0
Pod documented
20 1 my $self = shift;
21 1 my $isbn = shift;
22 1 $self->found(0);
23 1 $self->book(undef);
24
25 1 my $book;
26 1 $book->{isbn} = '';
27 1 $book->{author} = '';
28 1 $book->{title} = '';
29 1 $book->{book_link} = '';
30 1 $book->{image_link} = '';
31 1 $book->{pubdate} = '';
32 1 $book->{publisher} = '';
33 1 $book->{price} = '';
34 1 $book->{thumb_link} = '';
35 1 $book->{description} = ''; #return blank
36
37 1 my $ua = LWP::UserAgent->new();
38 1 my $search;
39 1 ▶ if (length($isbn) == 13) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $isbn == 13) { } 1 0 1
40 1 ▶ $search = $isbn =~ m/^97/ ? SEARCHBR : SEARCH;
Branch: 1 branch
BranchTrueFalseTotal
$isbn =~ /^97/ ? : 1 0 1
41 }
42 else {
43 0 ▶ $search = $isbn =~ m/^85/ ? SEARCHBR : SEARCH;
Branch: 1 branch
BranchTrueFalseTotal
$isbn =~ /^85/ ? : 0 0 0
44 }
45 1 my $res = $ua->request(GET $search . $isbn);
46 1 my $doc_html = $res->as_string;
47
48 1 ▶ if($doc_html =~ m{<td class="p5"><a href='((?:livro|importado).asp\?[^>]*orn=...&Tipo=2&ID=.*?)'><strong>(.+?)</strong>}igo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_html =~ m[<td class="p5"><a href='((?:livro|importado).asp\?[^>]*orn=...&Tipo=2&ID=.*?)'><strong>(.+?)</strong>]gio) { } 0 1 1
49 0 $book->{book_link} = 'http://www.siciliano.com.br/' . $1;
50 0 $book->{title} = $2;
51 0 $book->{isbn} = $isbn;
52 0 ▶ if($doc_html =~ m{<img src="(capas/.+?\....)" alt=""/>}io && $1 !~ m/default_pl/io) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc_html =~ m[<img src="(capas/.+?\....)" alt=""/>]io and not $1 =~ /default_pl/io) 0 0 0
Condition0%0/3
$doc_html =~ m[<img src="(capas/.+?\....)" alt=""/>]io and not $1 =~ /default_pl/io
!ll&&!rl&&r
000
MC/DC0%0/2
$doc_html =~ m[<img src="(capas/.+?\....)" alt=""/>]io and not $1 =~ /default_pl/io
$doc_html =~ m[<img src="(capas/.+?\....)" alt=""/>]io not $1 =~ /default_pl/io
Truth table0%0/3
A and not(B)
A= $doc_html =~ m[<img src="(capas/.+?\....)" alt=""/>]ioB= not $1 =~ /default_pl/io
ABresult
0X0
100
111
53 0 $book->{thumb_link} = SICILIANO . "/$1";
54 0 ($book->{image_link} = $book->{thumb_link}) =~ s/(\d+X?)p/$1/i;
55 0 ▶ $book->{image_link} = '' unless head($book->{image_link});
Branch: 1 branch
BranchTrueFalseTotal
unless &head($book->{"image_link"}) 0 0 0
56 }
57 0 ($book->{price}) = $doc_html =~ m{Por:<.*?R\$&nbsp;(.+?)<}igo;
58 0 ($book->{pubdate}) = $doc_html =~ m{>Edi..o: (\d+)<}igo;
59 0 ($book->{author}) = $doc_html =~ m{<strong class="azulescuro">(.+?)</strong>}igo;
60 0 ($book->{publisher}) = $doc_html =~ m{>Editora: (.+?)<}igo;
61 }
62 else {
63 1 return 0;
64 }
65
66 0 $self->found(1);
67 0 $self->book($book);
68 0 return $book;
69 }
70  
71 2 return 1;
72  
73  
74 __END__
↑ Summary