Business::ISBN - work with International Standard Book Numbers
use Business::ISBN;
$isbn_object = new Business::ISBN('1565922573'); $isbn_object = new Business::ISBN('1-56592-257-3');
#print the ISBN with hyphens at positions specified #by constructor print $isbn_object->as_string;
#print the ISBN with hyphens at specified positions. #this not does affect the default positions print $isbn_object->as_string([]);
#print the country code or publisher code print $isbn->country_code; print $isbn->publisher_code;
#check to see if the ISBN is valid $isbn_object->is_valid;
#fix the ISBN checksum. BEWARE: the error might not be #in the checksum! $isbn_object->fix_checksum;
# create an EAN13 barcode in PNG format $isbn_object->png_barcode;
#EXPORTABLE FUNCTIONS
use Business::ISBN qw( is_valid_checksum isbn_to_ean ean_to_isbn );
#verify the checksum if( is_valid_checksum('0123456789') eq Business::ISBN::GOOD_ISBN ) { ... }
#convert to EAN (European Article Number) $ean = isbn_to_ean('1565921496');
#convert from EAN (European Article Number) $isbn = ean_to_isbn('9781565921498');
The constructor accepts a scalar representing the ISBN.
The string representing the ISBN may contain characters
other than [0-9xX]
, although these will be removed in the
internal representation. The resulting string must look
like an ISBN - the first nine characters must be digits and
the tenth character must be a digit, 'x', or 'X'.
The constructor attempts to determine the country
code and the publisher code. If these data cannot
be determined, the constructor sets $obj->is_valid
to something other than GOOD_ISBN
.
An object is still returned and it is up to the program
to check $obj->is_valid
for one of five values (which
may be exported on demand). The actual values of these
symbolic versions are the same as those from previous
versions of this module which used literal values.
Business::ISBN::INVALID_PUBLISHER_CODE Business::ISBN::INVALID_COUNTRY_CODE Business::ISBN::BAD_CHECKSUM Business::ISBN::GOOD_ISBN Business::ISBN::BAD_ISBN
The string passed as the ISBN need not be a valid ISBN as
long as it superficially looks like one. This allows one to
use the fix_checksum()
method. Despite the disclaimer in
the discussion of that method, the author has found it
extremely useful. One should check the validity of the ISBN
with is_valid()
rather than relying on the return value
of the constructor. If all one wants to do is check the
validity of an ISBN, one can skip the object-oriented
interface and use the is_valid_checksum()
function
which is exportable on demand.
If the constructor decides it cannot create an object, it
returns undef
. It may do this if the string passed as the
ISBN cannot be munged to the internal format meaning that it
does not even come close to looking like an ISBN.
undef
if no publisher
code was found.
undef
if no country code
was found.
as_string
method provides
a way to temporarily override these positions and to even
forego them altogether.
Return the ISBN as a string. This function takes an optional anonymous array (or array reference) that specifies the placement of hyphens in the string. An empty anonymous array produces a string with no hyphens. An empty argument list automatically hyphenates the ISBN based on the discovered country and publisher codes. An ISBN that is not valid may produce strange results.
The positions specified in the passed anonymous array are only used for one method use and do not replace the values specified by the constructor. The method assumes that you know what you are doing and will attempt to use the least three positions specified. If you pass an anonymous array of several positions, the list will be sorted and the lowest three positions will be used. Positions less than 1 and greater than 9 are silently ignored.
A terminating 'x' is changed to 'X'.
Returns Business::ISBN::GOOD_ISBN
if the checksum is valid and the
country and publisher codes are defined.
Returns Business::ISBN::BAD_CHECKSUM
if the ISBN does not pass
the checksum test. The constructor accepts invalid ISBN's so that
they might be fixed with fix_checksum
.
Returns Business::ISBN::INVALID_COUNTRY_CODE
if a country code
could not be determined (relies on a valid checksum).
Returns Business::ISBN::INVALID_PUBLISHER_CODE
if a publisher code
could not be determined (relies on a valid checksum and country code).
Returns Business::ISBN::BAD_ISBN
if the string has no hope of ever
looking like a valid ISBN. This might include strings such as "abc"
,
"123456"
, and so on.
Some functions can be used without the object interface. These do not use object technology behind the scenes.
Business::ISBN::GOOD_ISBN
if the ISBN is valid, Business::ISBN::BAD_CHECKSUM
if the
string looks like an ISBN but has an invalid checksum, and
Business::ISBN::BAD_ISBN
if the string does not look like
an ISBN.
* The new EAN format has two prefixes for ISBNS (978, 979). The isbn_to_ean doesn't know which one to use, so it just uses 978
This module is on Sourceforge at http://perl-isbn.sourceforge.net/. You can download the lastest CVS source, submit bugs and patches, and watch the development. Of course, you can always write directly to the author. :)
* i would like to create the bar codes with the price extension
brian d foy <bdfoy@cpan.org>
Copyright 2001 brian d foy
Country code and publisher code graciously provided by Steve Fisher <stevef@teleord.co.uk> of Whitaker (the UK ISBN folks and the major bibliographic data provider in the UK). "Whitaker - helping to link authors to readers worldwide"
Thanks to Mark W. Eichin <eichin@thok.org> for suggestions and discussions on EAN support.
Thanks to Andy Lester <andy@petdance.com> for lots of bug fixes and testing.