Subject: | Errors when publisher id missing from book data (patch attached) |
Looking up a particular ISBN (see test in patch), produced results with
no publisher id. The existing scraper code assumes there is always an
id, and thus fails after fetching publisher data, and trying to
findnodes() on an empty result.
Patch contains test + code fix
Subject: | scraper_isbndb_patch.diff |
--- /usr/src/perl/cpanplus/5.10.0/build/WWW-Scraper-ISBN-ISBNdb_Driver-0.07/lib/WWW/Scraper/ISBN/ISBNdb_Driver.pm 2009-07-19 11:45:31.000000000 +0100
+++ ./lib/WWW/Scraper/ISBN/ISBNdb_Driver.pm 2009-03-13 03:50:26.000000000 +0000
@@ -117,19 +117,12 @@
my $pub_id = ($doc->findnodes('//PublisherText/@publisher_id'))[0]->to_literal;
- my $pub_data;
- if($pub_id) {
my $publisher = $self->_fetch( 'publishers', 'publisher_id', $pub_id, 'details' );
- $pub_data = ($publisher->findnodes('//PublisherData'))[0];
- }
+ my $data = ($publisher->findnodes('//PublisherData'))[0];
return {
- publisher => ($pub_data
- ? ($pub_data->findnodes('//Name'))[0]->to_literal
- : ''),
- location => ($pub_data
- ? ($pub_data->findnodes('//Details/@location'))[0]->to_literal
- : ''),
+ publisher => ($data->findnodes('//Name'))[0]->to_literal,
+ location => ($data->findnodes('//Details/@location'))[0]->to_literal,
year => $year || ''
};
}
--- /usr/src/perl/cpanplus/5.10.0/build/WWW-Scraper-ISBN-ISBNdb_Driver-0.07/t/02-missing.t 2009-07-19 11:47:49.000000000 +0100
+++ ./t/02-missing.t 1970-01-01 01:00:00.000000000 +0100
@@ -1,33 +0,0 @@
-#!perl -T
-
-use Test::More;
-
-my $access_key = $ENV{ISBNDB_ACCESS_KEY};
-
-if( $access_key ) {
- plan tests => 5;
-} else {
- plan skip_all => 'no isbndb.com access key provided in ISBNDB_ACCESS_KEY env variable';
-}
-
-use WWW::Scraper::ISBN;
-# use ExtUtils::MakeMaker;
-
-my $scraper = new WWW::Scraper::ISBN();
-$scraper->drivers( qw/ ISBNdb / );
-
-{
- no warnings;
- $WWW::Scraper::ISBN::ISBNdb_Driver::ACCESS_KEY = $access_key;
-}
-
-my( $res, $book );
-
-$res = $scraper->search( '9780141021621' );
-$book = $res->book;
-is( $book->{isbn}, '9780141021621', 'isbn' );
-is( $book->{title}, 'Skeleton Coast (Oregon Files 4)', 'title' );
-is( $book->{author}, '', 'author' );
-is( $book->{publisher}, '', 'publisher' );
-is( $book->{year}, '', 'year' );
-