From 26068ded7270bfe97c80a34b9dad7617fc712d3a Mon Sep 17 00:00:00 2001
From: Magnus Enger <magnus@libriotech.no>
Date: Wed, 4 May 2016 08:31:47 +0200
Subject: [PATCH] Bug 10756 - Carousel Display - Followup
Content-Type: text/plain; charset="utf-8"

On first testing this I got a 500 error saying "Can't call method
"is_valid" on an undefined value at /home/magnus/scripts/kohaclone/Koha/Carousel.pm
line 128." This was caused by a record with an ISBN of "979-10-91414-01-2".
The relevant code looks like this:
    my $isbn_obj = Business::ISBN->new($ii);
    my $isbn10;
    $isbn10 = $isbn_obj->as_isbn10;
    if ( $isbn10->is_valid() ) {...}
The documentation for Business::ISBN::as_isbn10 says: "Returns a new
ISBN object. If the object is already ISBN-10, this method clones it.
If it is an ISBN-13 with the prefix 978, it returns the ISBN-10
equivalent. For all other cases it returns undef." So for an ISBN that
starts with 979 like mine did, $isbn10 will be undef and we need to do
some extra checking before is_valid().

To test:
- Apply the first two patches on this bug and follow their test plan
- Make sure you have a new record with an ISBN that starts with 979
- Refresh the front page and observe the error
- Apply this patch
- Refresh the front page again and notice the absence of the error

Signed-off-by: Mason James <mtj@kohaaloha.com>
---
 Koha/Carousel.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Koha/Carousel.pm b/Koha/Carousel.pm
index ec6a7f7..ba6ac6b 100755
--- a/Koha/Carousel.pm
+++ b/Koha/Carousel.pm
@@ -125,7 +125,7 @@ sub GetRecentBibs {
 
             my $isbn10;
             $isbn10 = $isbn_obj->as_isbn10;
-            if ( $isbn10->is_valid() ) {
+            if ( $isbn10 && $isbn10->is_valid() ) {
                 $isbn = $isbn10->as_string( [] );
                 last;
             }
-- 
2.1.4