blib/lib/WWW/Search/GalerieIlonkaCZ.pm

filter: Statementstmt 46.4% 26 / 56 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 47.3% 35 / 74 CC 4 SCAR 14.0
CC
4
Cov
43%
native_retrieve_some
12.0
_fix_url
6.0
native_setup_search
2.0
CRAP 4.1
↑ Summary
1 package WWW::Search::GalerieIlonkaCZ;
2  
3 # Pragmas.
4 3 ▶use base qw(WWW::Search);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Modules.
9 3 ▶use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Web::Scraper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Constants.
15 3 Readonly::Scalar our $MAINTAINER => 'Michal Spacek <skim@cpan.org>';
16 3 Readonly::Scalar my $GILONKA_CZ => 'http://www.galerie-ilonka.cz';
17 3 Readonly::Scalar my $GILONKA_CZ_ACTION1 => '/galerie-ilonka/0/0/3/42/9/0/?hledatjak=2';
18  
19 # Version.
20 3 our $VERSION = 0.01;
21  
22 # Setup.
23 0 ▶sub native_setup_search {
Subroutine native_setup_search: not called CC=1 SCAR=6.9
Pod documented
24 0 my ($self, $query) = @_;
25 0 ▶ $self->{'_def'} = scraper {
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 process '//div[@id="incenterpage2"]/div'.
27 0 ▶ '/div[@class="productBody"]', 'books[]' => scraper {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28
29 0 process '//div[@class="productTitle"]/div/a',
30 'title' => 'TEXT';
31 # XXX Jak vybrat podtitul, kdyz tam je. Treba pri vyhledavani exlibris
32 # process '//div[@class="productTitle"]/div',
33 # 'subtitle' => 'RAW';
34 0 process '//div[@class="img_box"]/a', 'url' => '@href';
35 0 process '//div[@class="productText"]',
36 'description' => 'TEXT';
37 # XXX Cannot parse <link>. Breaks everything after this.
38 0 process '//div[@class="productPriceBox"]'.
39 '/div[@class="productPrice"]'.
40 '/span[@itemprop="price"]', 'price' => 'TEXT';
41 0 process '//div[@class="img_box"]/a/img',
42 'cover_url' => '@src';
43
44 0 return;
45 0 };
46 0 return;
47 0 };
48 0 $self->{'_query'} = $query;
49 0 return 1;
50 }
51  
52 # Get data.
53 0 ▶sub native_retrieve_some {
Subroutine native_retrieve_some: not called CC=3 SCAR=24.8
Pod documented
54 0 my $self = shift;
55  
56 # Query.
57 0 my $query = decode_utf8($self->{'_query'});
58  
59 # Get content.
60 0 my $ua = LWP::UserAgent->new(
61 'agent' => "WWW::Search::GalerieIlonkaCZ/$VERSION",
62 );
63 0 my $response = $ua->get($GILONKA_CZ.$GILONKA_CZ_ACTION1."&slovo=$query");
64  
65 # Process.
66 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
67 0 my $content = $response->content;
68  
69 # Get books structure.
70 0 my $books_hr = $self->{'_def'}->scrape($content);
71  
72 # Process each book.
73 0 foreach my $book_hr (@{$books_hr->{'books'}}) {
74 0 _fix_url($book_hr, 'url');
75 0 _fix_url($book_hr, 'cover_url');
76 0 push @{$self->{'cache'}}, $book_hr;
77 }
78 }
79  
80 0 return;
81 }
82  
83 # Fix URL to absolute path.
84 0 ▶sub _fix_url {
Subroutine _fix_url: not called CC=2 SCAR=17.9
85 0 my ($book_hr, $url) = @_;
86 0 ▶ if (exists $book_hr->{$url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $book_hr->{$url}) 0 0 0
87 0 $book_hr->{$url} = $GILONKA_CZ.$book_hr->{$url};
88 }
89 0 return;
90 }
91  
92 3 1;
93  
94 __END__
↑ Summary