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

filter: Statementstmt 24.6% 18 / 73 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod n/a totaltotal 20.5% 23 / 112 CC 17 SCAR 52.5
CC
17
Cov
17%
search
272.0
parse_authors
6.0
BEGIN
1.0
CRAP 190.0
↑ Summary
1 package WWW::Scraper::ISBN::LibUniverIt_Driver;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use WWW::Scraper::ISBN::Driver;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use HTML::Entities qw(decode_entities);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our @ISA = qw(WWW::Scraper::ISBN::Driver);
9  
10 2 our $VERSION = '0.13';
11
12 0 ▶sub search {
Subroutine search: not called CC=16 SCAR=56.1
13 0 my $self = shift;
14 0 my $isbn = shift;
15 0 $self->found(0);
16 0 $self->book(undef);
17
18 0 my $post_url = 'http://www.libreriauniversitaria.it/c_power_search.php?shelf=BIT&q=' . $isbn . '&submit=Invia';
19 0 my $ua = new LWP::UserAgent;
20 0 my $res = $ua->get($post_url);
21 0 my $doc = $res->as_string;
22
23 0 my $title = "";
24 0 my $authors = "";
25 0 my $editor = "";
26 0 my $date = "";
27 0 my $price = "";
28 0 my $pages = "";
29 0 my $series = "";
30 0 my $shelf = "";
31 0 my $trans = "";
32 0 ▶ if ($doc =~ /Nessun prodotto corrisponde ai criteri di ricerca/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($doc =~ /Nessun prodotto corrisponde ai criteri di ricerca/) { } 0 0 0
elsif ($doc =~ m[<title>Ricerca - $isbn - libreriauniversitaria\.it</title>]i) { } 0 0 0
elsif ($doc =~ /Dettagli del libro/) { } 0 0 0
33 0 $self->error("book not found.");
34 0 $self->found(0);
35 0 return 0;
36 } elsif ($doc =~ m|<title>Ricerca - $isbn - libreriauniversitaria\.it</title>|i){
37 0 my $info;
38 0 ▶ if ($doc =~ m|<td [^>]+><a [^>]+ class="product_heading_title_link" [^>]+>([^<]+)</a>(.*?)</td>|){
Branch: 1 branch
BranchTrueFalseTotal
if ($doc =~ m[<td [^>]+><a [^>]+ class="product_heading_title_link" [^>]+>([^<]+)</a>(.*?)</td>]) 0 0 0
39 0 $title = $1;
40 0 $info = $2;
41 0 $authors = parse_authors($info);
42 0 ▶ if ($info =~ m|<a[^>]+ href="libri-editore[^"]+" [^>]+/>([^<]+)</a> - (\d+)|){
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ m[<a[^>]+ href="libri-editore[^"]+" [^>]+/>([^<]+)</a> - (\d+)]) 0 0 0
43 0 $editor = $1;
44 0 $date = $2;
45 }
46 }
47
48 ##<span class="product_label">Editore:</span> <span class="product_text"><a href="libri-editore_Einaudi-einaudi.htm" title="Einaudi" >Einaudi</a></span>
49 0 ▶ $price = $1 if ($doc =~ /Prezzo: .*?&euro;&nbsp;(\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ /Prezzo: .*?&euro;&nbsp;(\d+)/ 0 0 0
50 } elsif ($doc =~ /Dettagli del libro/){
51 0 ▶ $price = $1 if ($doc =~ m|<span class="product_price">&euro;&nbsp;([^<]+)</span>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_price">&euro;&nbsp;([^<]+)</span>] 0 0 0
52 0 ▶ $title = $1 if ($doc =~ m|<span class="product_label">Titolo: </span>\n\t+\s+<span class="product_text">([^>]+)</span>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Titolo: </span>\n\t+\s+<span class="product_text">([^>]+)</span>] 0 0 0
53 0 ▶ $authors = parse_authors($1) if ($doc =~ m|<span class="product_label">Autor[ei]: </span>\n\t+\s+(.*?)\n\t+\s+</li>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Autor[ei]: </span>\n\t+\s+(.*?)\n\t+\s+</li>] 0 0 0
54 0 ▶ $editor = $1 if ($doc =~m|<span class="product_label">Editore: </span>\n\t+\s+<span class="product_text"><a class="publisher_url_html" href="http://www.libreriauniversitaria.it/libri-editore[^>]+>([^<]+)</a>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Editore: </span>\n\t+\s+<span class="product_text"><a class="publisher_url_html" href="http://www.libreriauniversitaria.it/libri-editore[^>]+>([^<]+)</a>] 0 0 0
55 0 ▶ $date = $1 if ($doc =~ m|<span class="product_label">Data di Pubblicazione: </span>\n\t+\s+<span class="product_text">(\d+)</span>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Data di Pubblicazione: </span>\n\t+\s+<span class="product_text">(\d+)</span>] 0 0 0
56 0 ▶ $pages = $1 if ($doc =~ m|<span class="product_label">Pagine: </span>\n\t+\s+<span class="product_text">(\d+)</span>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Pagine: </span>\n\t+\s+<span class="product_text">(\d+)</span>] 0 0 0
57 0 ▶ $series = $1 if ($doc =~ m|<span class="product_label">Collana: </span>\n\t+\s+<span class="product_text"><a class="publisher_url_html" href="http://www.libreriauniversitaria.it/libri-collana[^>]+>([^<]+)</a>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Collana: </span>\n\t+\s+<span class="product_text"><a class="publisher_url_html" href="http://www.libreriauniversitaria.it/libri-collana[^>]+>([^<]+)</a>] 0 0 0
58 0 ▶ $shelf = $1 if ($doc =~ m|<span class="product_label">Reparto: </span>\n\t+\s+<span class="product_text"><a class="reparto_url_html" href="http://www.libreriauniversitaria.it/libri[^>]+>([^<]+)</a>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Reparto: </span>\n\t+\s+<span class="product_text"><a class="reparto_url_html" href="http://www.libreriauniversitaria.it/libri[^>]+>([^<]+)</a>] 0 0 0
59 0 ▶ $trans = $1 if ($doc =~ m|<span class="product_label">Traduttore: </span>\n\t+\s+<span class="product_text">([^<]+)</span><li>|);
Branch: 1 branch
BranchTrueFalseTotal
if $doc =~ m[<span class="product_label">Traduttore: </span>\n\t+\s+<span class="product_text">([^<]+)</span><li>] 0 0 0
60
61 } else {
62 0 $self->error("libreriauniversitaria.it answered in an unattended way, book information cannot be found.");
63 0 $self->found(0);
64 };
65  
66 0 decode_entities($title);
67 0 decode_entities($authors);
68 0 decode_entities($editor);
69 0 my $bk = {
70 'isbn' => $isbn,
71 'author' => $authors,
72 'title' => $title,
73 'publisher' => $editor,
74 'date' => $date,
75 'price' => $price,
76 'pages' => $pages,
77 'series' => $series,
78 'shelf' => $shelf,
79 'trans' => $trans,
80 };
81 0 $self->book($bk);
82 0 $self->found(1);
83 0 return $bk;
84 }
85  
86 0 ▶sub parse_authors {
Subroutine parse_authors: not called CC=2 SCAR=17.9
87 0 my $info = shift;
88 0 my $sep = "";
89 0 my $authors;
90 0 ▶ while ($info =~ s|<a class="authors_url_html" href="http://www.libreriauniversitaria.it/libri-autore[^"]+" [^>]+>([^<]+)</a>||){
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ s[<a class="authors_url_html" href="http://www.libreriauniversitaria.it/libri-autore[^"]+" [^>]+>([^<]+)</a>][]) 0 0 0
91 0 $authors .= $sep . $1;
92 0 $sep = ", ";
93 }
94 0 return $authors;
95 }
96  
97 2 1;
98 __END__
↑ Summary