1Business::ISBN(3) User Contributed Perl Documentation Business::ISBN(3)
2
3
4
6 Business::ISBN - work with International Standard Book Numbers
7
9 use Business::ISBN;
10
11 # 10 digit ISBNs
12 $isbn10 = Business::ISBN->new('1565922573');
13 $isbn10 = Business::ISBN->new('1-56592-257-3');
14
15 # 13 digit ISBNs
16 $isbn13 = Business::ISBN->new('978-0-596-52724-2');
17
18 # convert
19 $isbn10 = $isbn13->as_isbn10; # for the 978 prefixes
20
21 $isbn13 = $isbn10->as_isbn13;
22
23 # maybe you don't care what it is as long as everything works
24 $isbn = Business::ISBN->new( $ARGV[0] );
25
26 #print the ISBN with hyphens at usual positions
27 print $isbn->as_string;
28
29 #print the ISBN with hyphens at specified positions.
30 #this not does affect the default positions
31 print $isbn->as_string([]);
32
33 #print the group code or publisher code
34 print $isbn->group_code;
35
36 print $isbn->publisher_code;
37
38 #check to see if the ISBN is valid
39 $isbn->is_valid;
40
41 #fix the ISBN checksum. BEWARE: the error might not be
42 #in the checksum!
43 $isbn->fix_checksum;
44
45 # create an EAN13 barcode in PNG format
46 $isbn->png_barcode;
47
49 This modules handles International Standard Book Numbers, including
50 ISBN-10 and ISBN-13.
51
52 Function interface
53 valid_isbn_checksum( ISBN10 | ISBN13 )
54 This function is exportable on demand, and works for either 10 or
55 13 character ISBNs).
56
57 use Business::ISBN qw( valid_isbn_checksum );
58
59 Returns 1 if the ISBN is a valid ISBN with the right checksum.
60
61 Returns 0 if the ISBN has valid prefix and publisher codes, but an
62 invalid checksum.
63
64 Returns undef if the ISBN does not validate for any other reason.
65
66 Object interface
67 new($isbn)
68 The constructor accepts a scalar representing the ISBN.
69
70 The string representing the ISBN may contain characters other than
71 "[0-9xX]", although these will be removed in the internal
72 representation. The resulting string must look like an ISBN - the
73 first nine characters must be digits and the tenth character must
74 be a digit, 'x', or 'X'.
75
76 The constructor attempts to determine the group code and the
77 publisher code. If these data cannot be determined, the
78 constructor sets "$obj->error" to something other than "GOOD_ISBN".
79 An object is still returned and it is up to the program to check
80 "$obj->error" for one of five values (which may be exported on
81 demand). The actual values of these symbolic versions are the same
82 as those from previous versions of this module which used literal
83 values.
84
85 Business::ISBN::INVALID_PUBLISHER_CODE
86 Business::ISBN::INVALID_GROUP_CODE
87 Business::ISBN::BAD_CHECKSUM
88 Business::ISBN::GOOD_ISBN
89 Business::ISBN::BAD_ISBN
90
91 If you have one of these values and want to turn it into a string,
92 you can use the %Business::ISBN::ERROR_TEXT hash, which is
93 exportable by asking for it explicitly in the import list.
94
95 use Business::ISBN qw(%ERROR_TEXT);
96
97 The string passed as the ISBN need not be a valid ISBN as long as
98 it superficially looks like one. This allows one to use the
99 "fix_checksum()" method. Despite the disclaimer in the discussion
100 of that method, the author has found it extremely useful. One
101 should check the validity of the ISBN with "is_valid()" rather than
102 relying on the return value of the constructor. If all one wants
103 to do is check the validity of an ISBN, one can skip the object-
104 oriented interface and use the "valid_isbn_checksum()" function
105 which is exportable on demand.
106
107 If the constructor decides it cannot create an object, it returns
108 "undef". It may do this if the string passed as the ISBN cannot be
109 munged to the internal format meaning that it does not even come
110 close to looking like an ISBN.
111
112 Instance methods
113 input_isbn
114 Returns the starting ISBN. Since you may insert hyphens or fix
115 checksums, you might want to see the original data.
116
117 common_data
118 Returns the starting ISBN after normalization, which removes
119 anything that isn't a digit or a valid checksum character.
120
121 isbn
122 Returns the current value of ISBN, even if it has an invalid
123 checksum. This is the raw data so it doesn't have the hyphens. If
124 you want hyphenation, try "as_string".
125
126 The "isbn" method should be the same as "as_string( [] )".
127
128 error
129 Return the error code for the reason the ISBN isn't valid. The
130 return value is a key in %ERROR_TEXT.
131
132 is_valid
133 Return true if the ISBN is valid, meaning that it has a valid
134 prefix (for ISBN-13), group code, and publisher code; and its
135 checksum validates.
136
137 type
138 Returns either "ISBN10" or "ISBN13".
139
140 prefix
141 Returns the prefix for the ISBN. This is currently either 978 or
142 979 for ISBN-13. It returns the empty string (so, a defined value)
143 for ISBN-10.
144
145 group_code
146 Returns the group code for the ISBN. This is the numerical version,
147 for example, '0' for the English group. The valid group codes come
148 from "Business::ISBN::Data".
149
150 group
151 Returns the group name for the ISBN. This is the string version.
152 For instance, 'English' for the '0' group. The names come from
153 "Business::ISBN::Data".
154
155 publisher_code
156 Returns the publisher code for the ISBN. This is the numeric
157 version, for instance '596' for O'Reilly Media.
158
159 article_code
160 Returns the article code for the ISBN. This is the numeric version
161 that uniquely identifies the item.
162
163 checksum
164 Returns the checksum code for the ISBN. This checksum may not be
165 valid since you can create an object an fix the checksum later with
166 "fix_checksum".
167
168 is_valid_checksum
169 Returns "Business::ISBN::GOOD_ISBN" for valid checksums and
170 "Business::ISBN::BAD_CHECKSUM" otherwise. This does not guarantee
171 that the rest of the ISBN is actually assigned to a book.
172
173 fix_checksum
174 Checks the checksum and modifies the ISBN to set it correctly if
175 needed.
176
177 as_string(), as_string([])
178 Return the ISBN as a string. This function takes an optional
179 anonymous array (or array reference) that specifies the placement
180 of hyphens in the string. An empty anonymous array produces a
181 string with no hyphens. An empty argument list automatically
182 hyphenates the ISBN based on the discovered group and publisher
183 codes. An ISBN that is not valid may produce strange results.
184
185 The positions specified in the passed anonymous array are only used
186 for one method use and do not replace the values specified by the
187 constructor. The method assumes that you know what you are doing
188 and will attempt to use the least three positions specified. If
189 you pass an anonymous array of several positions, the list will be
190 sorted and the lowest three positions will be used. Positions less
191 than 1 and greater than 12 are silently ignored.
192
193 A terminating 'x' is changed to 'X'.
194
195 as_isbn10
196 Returns a new ISBN object. If the object is already ISBN-10, this
197 method clones it. If it is an ISBN-13 with the prefix 978, it
198 returns the ISBN-10 equivalent. For all other cases it returns
199 undef.
200
201 as_isbn13
202 Returns a new ISBN object. If the object is already ISBN-13, this
203 method clones it. If it is an ISBN-10, it returns the ISBN-13
204 equivalent with the 978 prefix.
205
206 xisbn
207 In scalar context, returns an anonymous array of related ISBNs
208 using xISBN. In list context, returns a list.
209
210 This feature requires "LWP::Simple".
211
212 png_barcode
213 Returns image data in PNG format for the barcode for the ISBN. This
214 works with ISBN-10 and ISBN-13. The ISBN-10s are automaically
215 converted to ISBN-13.
216
217 This requires "GD::Barcode::EAN13".
218
221 * i would like to create the bar codes with the price extension
222
224 This source is in Github:
225
226 https://github.com/briandfoy/business--isbn
227
229 brian d foy "<bdfoy@cpan.org>"
230
232 Copyright (c) 2001-2013, brian d foy, All Rights Reserved.
233
234 You may redistribute this under the same terms as Perl itself.
235
237 Thanks to Mark W. Eichin "<eichin@thok.org>" for suggestions and
238 discussions on EAN support.
239
240 Thanks to Andy Lester "<andy@petdance.com>" for lots of bug fixes and
241 testing.
242
243 Ed Summers "<esummers@cpan.org>" has volunteered to help with this
244 module.
245
246
247
248perl v5.16.3 2013-05-31 Business::ISBN(3)