]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Utils/ISBN.pm
Add OILS_SIP_MSG_BILL_ERR for when an error occurs getting bills.
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / Utils / ISBN.pm
1 package OpenILS::Utils::ISBN;
2
3 # ---------------------------------------------------------------
4 # Copyright (C) 2010 Equinox Software, Inc
5 # Author: Joe Atzberger <jatzberger@esilibrary.com>
6 #
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.
11
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 # ---------------------------------------------------------------
17
18 use strict;
19 use warnings;
20
21 use Business::ISBN;
22
23 use base qw/Exporter/;
24 our $VERSION = '0.01';
25 our @EXPORT_OK = qw/isbn_upconvert/;
26
27 # Jason Stephenson <jstephenson@mvlc.org> at Merrimack Valley Library Consortium
28 # Dan Scott <dscott@laurentian.ca> at Laurentian University
29
30 sub isbn_upconvert {
31     my $in     = @_ ? shift : return;
32     my $pretty = @_ ? shift : 0;
33     $in =~ s/\s*//g;
34     $in =~ s/-//g;
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;
40 }
41
42 1;
43 __END__
44
45 For example, if you have a file isbns.txt with these lines:
46
47 1598884093
48  1598884093
49  15  988  840 93     
50 0446357197
51   0 446 3 5  7 1 9        7
52   0 446 3 5  7 1 9        1
53 0596526857
54 0786222735
55 0446360015
56 0446350109
57 0446314129
58 0439139597
59 0743294394
60 159143047X
61 1590203097
62 075480965X
63 0393048799
64 0446831832
65 0446310069
66 1598883275
67 0446313033
68 0446360279
69
70 And you run:
71     perl -pe 'use OpenILS::Utils::ISBN qw/isbn_upconvert/; $_ = isbn_upconvert($_) . "\n";' <isbns.txt
72
73 You get this output:
74 9781598884098
75 9781598884098
76 9781598884098
77 9780446357197
78 9780446357197
79 9780446357197
80 9780596526856
81 9780786222735
82 9780446360012
83 9780446350105
84 9780446314121
85 9780439139595
86 9780743294393
87 9781591430476
88 9781590203095
89 9780754809654
90 9780393048797
91 9780446831833
92 9780446310062
93 9781598883275
94 9780446313032
95 9780446360272
96