use Business::ISMN; $ismn_object = new Business::ISMN('M021765430'); $ismn_object = new Business::ISMN('M-021-76543-0'); #print the ISMN with hyphens at positions specified #by constructor print $ismn_object->as_string; #print the ISMN with hyphens at specified positions. #this not does affect the default positions print $ismn_object->as_string([]); #print the publication country or publisher code print $ismn->country; # two letter country string print $ismn->publisher_code; # digits #check to see if the ISMN is valid $ismn_object->is_valid; #fix the ISMN checksum. BEWARE: the error might not be #in the checksum! $ismn_object->fix_checksum; # create an EAN13 barcode in PNG format $ismn_object->png_barcode; #EXPORTABLE FUNCTIONS use Business::ISMN qw( is_valid_checksum ismn_to_ean ean_to_ismn ); #verify the checksum if( is_valid_checksum('0123456789') eq Business::ISMN::GOOD_ISMN ) { ... } #convert to EAN (European Article Number) $ean = ismn_to_ean('1565921496'); #convert from EAN (European Article Number) $ismn = ean_to_ismn('9781565921498');
The string representing the ISMN may contain characters other than "[0-9mM]", although these will be removed in the internal representation. The resulting string must look like an ISMN - the first character is an 'M' and the following nine characters must be digits.
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_ISMN". 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::ISMN::INVALID_PUBLISHER_CODE Business::ISMN::BAD_CHECKSUM Business::ISMN::GOOD_ISMN Business::ISMN::BAD_ISMN
The string passed as the ISMN need not be a valid ISMN 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 ISMN 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 ISMN, 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 ISMN cannot be munged to the internal format meaning that it does not even come close to looking like an ISMN.
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.
Returns "Business::ISMN::BAD_CHECKSUM" if the ISMN does not pass the checksum test. The constructor accepts invalid ISMN's so that they might be fixed with "fix_checksum".
Returns "Business::ISMN::INVALID_PUBLISHER_CODE" if a publisher code could not be determined.
Returns "Business::ISMN::BAD_ISMN" if the string has no hope of ever looking like a valid ISMN. This might include strings such as "abc", "123456", and so on.
This method was formerly called "is_valid_publisher_code". That's deprecated but still there.
https://github.com/briandfoy/business-ismn/
You may redistribute this under the terms of the Artistic License 2.0.