1 package OpenILS::Utils::ISBN;
3 # ---------------------------------------------------------------
4 # Copyright (C) 2010 Equinox Software, Inc
5 # Author: Joe Atzberger <jatzberger@esilibrary.com>
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 # ---------------------------------------------------------------
23 use base qw/Exporter/;
24 our $VERSION = '0.01';
25 our @EXPORT_OK = qw/isbn_upconvert/;
27 # Jason Stephenson <jstephenson@mvlc.org> at Merrimack Valley Library Consortium
28 # Dan Scott <dscott@laurentian.ca> at Laurentian University
31 my $in = @_ ? shift : return;
32 my $pretty = @_ ? shift : 0;
35 length($in) or return;
36 my $isbn = Business::ISBN->new($in) or return;
37 $isbn->fix_checksum() if $isbn->is_valid_checksum() == Business::ISBN::BAD_CHECKSUM;
38 $isbn->is_valid() or return;
39 return $pretty ? $isbn->as_isbn13->as_string : $isbn->as_isbn13->isbn;
45 For example, if you have a file isbns.txt with these lines:
71 perl -pe 'use OpenILS::Utils::ISBN qw/isbn_upconvert/; $_ = isbn_upconvert($_) . "\n";' <isbns.txt