blib/lib/WWW/Search/ValentinskaCZ.pm

filter: Statementstmt 46.7% 29 / 62 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 100% 2 / 2 totaltotal 47.5% 39 / 82 SCAR 19.2
CC
4
Cov
44%
native_retrieve_some
12.0
__ANON__
6.0
native_setup_search
2.0
CRAP 6.8
↑ Summary
1 package WWW::Search::ValentinskaCZ;
2  
3 # Pragmas.
4 2 ▶use base qw(WWW::Search);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Modules.
9 2 ▶use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Web::Scraper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Constants.
16 2 Readonly::Scalar our $MAINTAINER => 'Michal Spacek <skim@cpan.org>';
17 2 Readonly::Scalar my $VALENTINSKA_CZ => 'http://www.valentinska.cz/';
18 2 Readonly::Scalar my $VALENTINSKA_CZ_ACTION1 => 'index.php?route=product/search&search=';
19  
20 # Version.
21 2 our $VERSION = 0.03;
22  
23 # Setup.
24 sub native_setup_search {
25 0 ▶ my ($self, $query) = @_;
Subroutine native_setup_search: not called CC=1 SCAR=6.9
Pod documented
26 $self->{'_def'} = scraper {
27  
28 # Get list of books.
29 process '//div[@class="product-inner clearfix"]',
30 'books[]' => scraper {
31  
32 0 ▶ process '//div[@class="wrap-infor"]/div[@class="name"]/a',
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 'title' => 'TEXT';
34 process '//div[@class="wrap-infor"]/div[@class="name"]/a',
35 'url' => ['@href', sub {
36 0 ▶ my $url = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
37 0 my $uri = URI->new($url);
38 0 my %query = $uri->query_form;
39 0 ▶ if (exists $query{'search'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $query{"search"}) 0 0 0
40 0 delete $query{'search'};
41 }
42 0 $uri->query_form(\%query);
43 0 return $uri->as_string;
44 0 }];
45 0 process '//div[@class="image"]/a/img',
46 'image' => '@src';
47 0 process '//div[@class="wrap-infor"]/div[@class="author"]',
48 'author' => 'TEXT';
49 process '//div[@class="wrap-infor"]/div[@class="price"]/br/preceding-sibling::text()',
50 0 ▶ 'price' => ['TEXT', sub { s/^\s*(.*?)\s*$/$1/; }];
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 return;
52 0 ▶ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 return;
54 0 };
55 0 $self->{'_query'} = $query;
56 0 return 1;
57 }
58  
59 # Get data.
60 sub native_retrieve_some {
61 0 ▶ my $self = shift;
Subroutine native_retrieve_some: not called CC=3 SCAR=24.8
Pod documented
62  
63 # Query.
64 0 my $query = decode_utf8($self->{'_query'});
65  
66 # Get content.
67 0 my $ua = LWP::UserAgent->new(
68 'agent' => "WWW::Search::ValentinskaCZ/$VERSION",
69 );
70 0 my $query_url = $VALENTINSKA_CZ.$VALENTINSKA_CZ_ACTION1.$query;
71 0 my $response = $ua->get($query_url);
72  
73 # Process.
74 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
75 0 my $content = $response->content;
76  
77 # Get books structure.
78 0 my $books_hr = $self->{'_def'}->scrape($content);
79  
80 # Process each book.
81 0 foreach my $book_hr (@{$books_hr->{'books'}}) {
82 0 push @{$self->{'cache'}}, $book_hr;
83 }
84 }
85  
86 0 return;
87 }
88  
89 2 1;
90  
91 __END__
↑ Summary