When getting ISBNs from the database, they often contain extra stuff
after the ISBN that sometimes causes problems for Business::ISBN.
This commit attempts to resolve some of that by looking only for the
part of the ISBN data that resembles an ISBN and using just that part.
If the ISBN data doesn't look like an ISBN, then it is discarded.
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
my @upcs = grep {$_->{tag} eq '024'} @$key_data;
map {
- my $isbn_obj = Business::ISBN->new($_->{value});
- my $isbn_str;
- $isbn_str = $isbn_obj->as_string([]) if defined($isbn_obj);
- $_->{value} = $isbn_str;
+ # Attempt to validate the ISBN.
+ # strip out hyphens;
+ $_->{value} =~ s/-//g;
+ #pull out the first chunk that looks like an ISBN:
+ if ($_->{value} =~ /([0-9xX]{10}(?:[0-9xX]{3})?)/) {
+ $_->{value} = $1;
+ my $isbn_obj = Business::ISBN->new($_->{value});
+ my $isbn_str;
+ $isbn_str = $isbn_obj->as_string([]) if defined($isbn_obj);
+ $_->{value} = $isbn_str;
+ } else {
+ undef $_->{value};
+ }
undef $_ if !defined($_->{value});
} @isbns;