Business::ISBN (3)
Leading comments
Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) Standard preamble: ========================================================================
NAME
Business::ISBN - work with International Standard Book NumbersSYNOPSIS
use Business::ISBN; # 10 digit ISBNs $isbn10 = Business::ISBN->new('1565922573'); $isbn10 = Business::ISBN->new('1-56592-257-3'); # 13 digit ISBNs $isbn13 = Business::ISBN->new('978-0-596-52724-2'); # convert $isbn10 = $isbn13->as_isbn10; # for the 978 prefixes $isbn13 = $isbn10->as_isbn13; # maybe you don't care what it is as long as everything works $isbn = Business::ISBN->new( $ARGV[0] ); #print the ISBN with hyphens at usual positions print $isbn->as_string; #print the ISBN with hyphens at specified positions. #this not does affect the default positions print $isbn->as_string([]); #print the group code or publisher code print $isbn->group_code; print $isbn->publisher_code; #check to see if the ISBN is valid $isbn->is_valid; #fix the ISBN checksum. BEWARE: the error might not be #in the checksum! $isbn->fix_checksum; # create an EAN13 barcode in PNG format $isbn->png_barcode;
DESCRIPTION
This modules handles International Standard Book Numbers, includingFunction interface
- valid_isbn_checksum( ISBN10|ISBN13)
-
This function is exportable on demand, and works for either 10
or 13 character ISBNs).
use Business::ISBN qw( valid_isbn_checksum );
Returns 1 if the
ISBNis a validISBNwith the right checksum.Returns 0 if the
ISBNhas valid prefix and publisher codes, but an invalid checksum.Returns undef if the
ISBNdoes not validate for any other reason.
Object interface
- new($isbn)
-
The constructor accepts a scalar representing the ISBN.
The string representing the
ISBNmay contain characters other than "[0-9xX]", although these will be removed in the internal representation. The resulting string must look like anISBN -the first nine characters must be digits and the tenth character must be a digit, 'x', or 'X'.The constructor attempts to determine the group code and the publisher code. If these data cannot be determined, the constructor sets "$obj->error" to something other than "GOOD_ISBN". An object is still returned and it is up to the program to check the "error" method for one of five values or one of the "error_*" methods to check for a particular error. 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_GROUP_CODE Business::ISBN::BAD_CHECKSUM Business::ISBN::GOOD_ISBN Business::ISBN::BAD_ISBN
If you have one of these values and want to turn it into a string, you can use the %Business::ISBN::ERROR_TEXT hash, which is exportable by asking for it explicitly in the import list:
use Business::ISBN qw(%ERROR_TEXT);
As of version 2.010_01, you can get this text from "error_text" so you don't have to import anything.
The string passed as the
ISBNneed not be a validISBNas 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 theISBNwith "is_valid()" rather than relying on the return value of the constructor. If all one wants to do is check the validity of anISBN,one can skip the object-oriented interface and use the "valid_isbn_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
ISBNcannot be munged to the internal format meaning that it does not even come close to looking like anISBN.
Instance methods
- input_isbn
-
Returns the starting ISBN.Since you may insert hyphens or fix checksums, you might want to see the original data.
- common_data
-
Returns the starting ISBNafter normalization, which removes anything that isn't a digit or a valid checksum character.
- isbn
-
Returns the current value of ISBN,even if it has an invalid checksum. This is the raw data so it doesn't have the hyphens. If you want hyphenation, try "as_string".
The "isbn" method should be the same as "as_string( [] )".
- error
-
Return the error code for the reason the ISBNisn't valid. The return value is a key in %ERROR_TEXT.
- error_is_bad_group
- error_is_bad_publisher
- error_is_article_out_of_range
- error_is_bad_checksum
-
Returns true if the ISBNerror is that type.
- error_text
- Returns a text version of the error text
- is_valid
-
Return true if the ISBNis valid, meaning that it has a valid prefix (forISBN-13), group code, and publisher code; and its checksum validates.
- type
- Returns either "ISBN10" or "ISBN13".
- prefix
-
Returns the prefix for the ISBN.This is currently either 978 or 979 forISBN-13.It returns the empty string (so, a defined value) forISBN-10.
- group_code
-
Returns the group code for the ISBN.This is the numerical version, for example, '0' for the English group. The valid group codes come from "Business::ISBN::Data".
- group
-
Returns the group name for the ISBN.This is the string version. For instance, 'English' for the '0' group. The names come from "Business::ISBN::Data".
- publisher_code
-
Returns the publisher code for the ISBN.This is the numeric version, for instance '596' for O'Reilly Media.
- article_code
-
Returns the article code for the ISBN.This is the numeric version that uniquely identifies the item.
- article_code_length
-
Returns the article code length for the ISBN.
- article_code_min
- Returns the minimum article code length for the publisher code.
- article_code_max
- Returns the max article code length for the publisher code.
- checksum
-
Returns the checksum code for the ISBN.This checksum may not be valid since you can create an object an fix the checksum later with "fix_checksum".
- is_valid_checksum
-
Returns "Business::ISBN::GOOD_ISBN" for valid checksums and
"Business::ISBN::BAD_CHECKSUM" otherwise. This does not guarantee
that the rest of the ISBNis actually assigned to a book.
- fix_checksum
-
Checks the checksum and modifies the ISBNto set it correctly if needed.
- as_string(), as_string([])
-
Return the ISBNas 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 theISBNbased on the discovered group and publisher codes. AnISBNthat 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 12 are silently ignored.
A terminating 'x' is changed to 'X'.
- as_isbn10
-
Returns a new ISBNobject. If the object is alreadyISBN-10,this method clones it. If it is anISBN-13with the prefix 978, it returns theISBN-10equivalent. For all other cases it returns undef.
- as_isbn13
-
Returns a new ISBNobject. If the object is alreadyISBN-13,this method clones it. If it is anISBN-10,it returns theISBN-13equivalent with the 978 prefix.
- increment
-
Returns the next "Business::ISBN" by incrementing the article code of
the specified ISBN(object or scalar).
Returns undef, if the parameter is invalid or equals the maximum possible
ISBNfor the publisher.$isbn = Business::ISBN->new('1565922573'); # 1-56592-257-3 $next_isbn = $isbn->increment; # 1-56592-258-1
If the next article code would exceed the maximum possible article code (such as incrementing 999 to 1000), this returns
ARTICLE_CODE_OUT_OF_RANGEas the error. - decrement
-
Returns the previous "Business::ISBN" by decrementing the article
code of the specified ISBN(object or scalar).
Returns undef, if the parameter is invalid or equals the minimum possible
ISBNfor the publisher.$isbn = Business::ISBN->new('1565922573'); # 1-56592-257-3 $prev_isbn = $isbn->decrement; # 1-56592-256-5
If the next article code would exceed the maximum possible article code (such as incrementing 000 to -1), this returns
ARTICLE_CODE_OUT_OF_RANGEas the error. - png_barcode
-
Returns image data in PNGformat for the barcode for theISBN.This works withISBN-10andISBN-13.The ISBN-10s are automaically converted toISBN-13.
This requires "GD::Barcode::EAN13".
BUGS
TO DO
* i would like to create the bar codes with the price extensionSOURCE AVAILABILITY
This source is in Github:
github.com/briandfoy/business-isbn
AUTHOR
brian d foy "<bdfoy@cpan.org>"COPYRIGHT AND LICENSE
Copyright © 2001-2016, brian d foy <bdfoy@cpan.org>. All rights reserved.This module is licensed under the Artistic License 2.0. See the
CREDITS
Thanks to Mark W. Eichin "<eichin@thok.org>" for suggestions and discussions onThanks to Andy Lester "<andy@petdance.com>" for lots of bug fixes and testing.
Ed Summers "<esummers@cpan.org>" has volunteered to help with this module.
Markus Spann "<markus_spann@gmx.de>" added "increment" and "decrement".