blib/lib/WWW/Search/ISBNDB.pm

filter: Statementstmt 37.5% 24 / 64 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 34.0% 34 / 100 CC 11 SCAR 37.4
CC
11
Cov
29%
native_retrieve_some
90.0
url_encode
6.0
native_setup_search
6.0
CRAP 42.0
↑ Summary
1 # $Id: $ $Revision: $ $Source: $ $Date: $
2  
3 package WWW::Search::ISBNDB;
4  
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 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use WWW::Search qw(generic_option);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use WWW::SearchResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 @ISA = qw(WWW::Search);
16 3 $VERSION = '0.3';
17  
18 0 ▶sub url_encode {
Subroutine url_encode: not called CC=2 SCAR=17.9
Pod documented
19 0 my ($encode ) = @_;
20 0 ▶ if (! $encode) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($encode) 0 0 0
21 0 $encode =~ s/([^A-Za-z0-9\-_.!~*'() ])/ uc sprintf "%%%02x",ord $1 /xmeg;
22 0 $encode =~ tr/ /+/;
23 0 return $encode;
24 }
25  
26 0 ▶sub native_setup_search {
Subroutine native_setup_search: not called CC=2 SCAR=17.9
Pod documented
27 0 my($self, $query) = @_;
28 0 ▶ if (! $self->{'key'}) { die 'No license key given to WWW::Search::ISBDB!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"key"}) 0 0 0
29 0 $self->{'_offset'} = 0;
30 0 $self->{'_query'} = $query;
31 0 return 1;
32 }
33  
34 0 ▶sub native_retrieve_some {
Subroutine native_retrieve_some: not called CC=9 SCAR=45.0
Pod documented
35 0 my ($self) = @_;
36
37 # HACK: Consider better url encoding.
38 0 my $query = url_encode( $self->{'_query'} );
39  
40 my %args = (
41 'access_key' => $self->{'key'},
42 'index1' => $self->{'_type'} || 'combined',
43 0 ▶ 'value1' => $self->{'_query'},
Condition0%0/2
$self->{'_type'} || 'combined'
l!l
00
MC/DC0%0/1
$self->{'_type'} || 'combined'
$self->{'_type'}
Truth table0%0/2
A
A= $self->{'_type'}
Aresult
11
00
44 'results' => 'details+subjects+texts',
45 );
46
47 0 my $url = 'http://isbndb.com/api/books.xml?'.( join q{&}, map { $_ . q{=} . $args{$_} } keys %args );
48  
49 0 my $ua = LWP::UserAgent->new(
50 'agent' => "W3SearchISBNDB/$VERSION",
51 );
52 0 my $response = $ua->get( $url );
53  
54 0 ▶ if (! $response->is_success ) { return; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
55 0 my $content = $response->content;
56 0 ▶ if ( $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 0 0 0
57 0 my $xs = new XML::Simple();
58 0 my $ref = $xs->XMLin("$content" );
59 0 foreach my $book ( @{ $ref->{'BookList'}{'BookData'} }) {
60 0 my $hit = WWW::SearchResult->new();
61 0 $hit->{'book_id'} = $book->{'book_id'};
62 0 $hit->{'isbn'} = $book->{'isbn'};
63 0 ▶ $hit->{'language'} = $book->{'Details'}{'language'} || q{};
Condition0%0/2
$book->{'Details'}{'language'} || ''
l!l
00
MC/DC0%0/1
$book->{'Details'}{'language'} || ''
$book->{'Details'}{'language'}
Truth table0%0/2
A
A= $book->{'Details'}{'language'}
Aresult
11
00
64 0 ▶ $hit->{'summary'} = $book->{'Summary'} || q{};
Condition0%0/2
$book->{'Summary'} || ''
l!l
00
MC/DC0%0/1
$book->{'Summary'} || ''
$book->{'Summary'}
Truth table0%0/2
A
A= $book->{'Summary'}
Aresult
11
00
65 0 ▶ $hit->{'titlelong'} = $book->{'TitleLong'} || q{};
Condition0%0/2
$book->{'TitleLong'} || ''
l!l
00
MC/DC0%0/1
$book->{'TitleLong'} || ''
$book->{'TitleLong'}
Truth table0%0/2
A
A= $book->{'TitleLong'}
Aresult
11
00
66 0 ▶ $hit->{'notes'} = $book->{'Notes'} || q{};
Condition0%0/2
$book->{'Notes'} || ''
l!l
00
MC/DC0%0/1
$book->{'Notes'} || ''
$book->{'Notes'}
Truth table0%0/2
A
A= $book->{'Notes'}
Aresult
11
00
67 0 $hit->title( $book->{'Title'} );
68 0 $hit->url( 'http://isbndb.com/search-all.html?kw=' . $book->{'isbn'} );
69 0 push @{$self->{cache}}, $hit;
70 }
71 }
72  
73 0 return;
74 }
75  
76 3 1;
77 __END__
↑ Summary