blib/lib/WWW/Search/AntikvariatJudaicaCZ.pm

filter: Statementstmt 45.6% 26 / 57 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 46.6% 35 / 75 SCAR 19.5
CC
4
Cov
43%
native_retrieve_some
12.0
_fix_url
6.0
native_setup_search
2.0
CRAP 7.0
↑ Summary
1 package WWW::Search::AntikvariatJudaicaCZ;
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 LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Web::Scraper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use WWW::Search qw(generic_option);
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 $BASE_URL => 'http://antikvariat-judaica.cz/';
17 3 Readonly::Scalar my $ACTION1 => 'search/node/';
18  
19 # Version.
20 3 our $VERSION = 0.01;
21  
22 # Setup.
23 sub native_setup_search {
24 0 ▶ my ($self, $query) = @_;
Subroutine native_setup_search: not called CC=1 SCAR=6.9
Pod documented
25 $self->{'_def'} = scraper {
26 process '//div[@class="content"]/dl/div', 'books[]' => scraper {
27 0 ▶ process '//h2/a', 'title' => 'TEXT';
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 process '//h2/a', 'url' => '@href';
29 0 process '//img[@class="imagecache '.
30 'imagecache-product_list"]',
31 'cover_url' => '@src';
32 0 process '//div[@class="field sell-price"]',
33 'price' => 'TEXT';
34 0 process '//div[@class="field '.
35 'field-type-content-taxonomy '.
36 'field-field-author"]',
37 'author' => 'TEXT';
38 0 return;
39 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 return;
41 0 };
42 0 $self->{'_query'} = $query;
43 0 return 1;
44 }
45  
46 # Get data.
47 sub native_retrieve_some {
48 0 ▶ my $self = shift;
Subroutine native_retrieve_some: not called CC=3 SCAR=24.8
Pod documented
49  
50 # Get content.
51 0 my $ua = LWP::UserAgent->new(
52 'agent' => "WWW::Search::AntikvariatJudaicaCZ/$VERSION",
53 );
54 0 my $response = $ua->get($BASE_URL.$ACTION1.$self->{'_query'});
55  
56 # Process.
57 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
58 0 my $content = $response->content;
59  
60 # Get books structure.
61 0 my $books_hr = $self->{'_def'}->scrape($content);
62  
63 # Process each book.
64 0 foreach my $book_hr (@{$books_hr->{'books'}}) {
65 0 _fix_url($book_hr, 'url');
66 0 $book_hr->{'price'} =~ s/\N{U+00A0}/ /ms;
67 0 $book_hr->{'price'} =~ s/^\s*Cena:\s*//ms;
68 0 $book_hr->{'author'} =~ s/^\s*Autor:\s*//ms;
69 0 push @{$self->{'cache'}}, $book_hr;
70 }
71 }
72  
73 0 return;
74 }
75  
76 # Fix URL to absolute path.
77 sub _fix_url {
78 0 ▶ my ($book_hr, $url) = @_;
Subroutine _fix_url: not called CC=2 SCAR=17.9
79 0 ▶ if (exists $book_hr->{$url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $book_hr->{$url}) 0 0 0
80 0 $book_hr->{$url} = $BASE_URL.$book_hr->{$url};
81 }
82 0 return;
83 }
84  
85 3 1;
86  
87 __END__
↑ Summary