SYNOPSIS

        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 publisher or publisher code
        print $ismn->publisher;
        print $ismn->publisher_code;

        #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');

DESCRIPTION

Methods

new($ismn)

The constructor accepts a scalar representing the \s-1ISMN\s0. The string representing the \s-1ISMN\s0 may contain characters other than \*(C`[0-9mM]\*(C', although these will be removed in the internal representation. The resulting string must look like an \s-1ISMN\s0 - 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 \*(C`$obj->is_valid\*(C' to something other than \*(C`GOOD_ISMN\*(C'. An object is still returned and it is up to the program to check \*(C`$obj->is_valid\*(C' 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 \s-1ISMN\s0 need not be a valid \s-1ISMN\s0 as long as it superficially looks like one. This allows one to use the \*(C`fix_checksum()\*(C' method. Despite the disclaimer in the discussion of that method, the author has found it extremely useful. One should check the validity of the \s-1ISMN\s0 with \*(C`is_valid()\*(C' rather than relying on the return value of the constructor. If all one wants to do is check the validity of an \s-1ISMN\s0, one can skip the object-oriented interface and use the \*(C`is_valid_checksum()\*(C' function which is exportable on demand. If the constructor decides it cannot create an object, it returns \*(C`undef\*(C'. It may do this if the string passed as the \s-1ISMN\s0 cannot be munged to the internal format meaning that it does not even come close to looking like an \s-1ISMN\s0.

ismn

Returns the \s-1ISMN\s0 as a string

publisher

Returns the country associated with the publisher code.

publisher_code

Returns the publisher code or \*(C`undef\*(C' if no publisher code was found.

article_code

Returns the article code or \*(C`undef\*(C' if no article code was found.

checksum

Returns the checksum or \*(C`undef\*(C' if no publisher code was found.

hyphen_positions

Returns the list of hyphen positions as determined from the country and publisher codes. the \*(C`as_string\*(C' method provides a way to temporarily override these positions and to even forego them altogether.

as_string(), as_string([])

Return the \s-1ISMN\s0 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 \s-1ISMN\s0 based on the discovered publisher code. An \s-1ISMN\s0 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.

is_valid

Returns \*(C`Business::ISMN::GOOD_ISMN\*(C' if the checksum is valid and the country and publisher codes are defined. Returns \*(C`Business::ISMN::BAD_CHECKSUM\*(C' if the \s-1ISMN\s0 does not pass the checksum test. The constructor accepts invalid \s-1ISMN\s0's so that they might be fixed with \*(C`fix_checksum\*(C'. Returns \*(C`Business::ISMN::INVALID_PUBLISHER_CODE\*(C' if a publisher code could not be determined. Returns \*(C`Business::ISMN::BAD_ISMN\*(C' if the string has no hope of ever looking like a valid \s-1ISMN\s0. This might include strings such as "abc", "123456", and so on.

is_valid_publisher_code

Returns true if the publisher code is valid, and false otherwise.

fix_checksum()

Replace the tenth character with the checksum the corresponds to the previous nine digits. This does not guarantee that the \s-1ISMN\s0 corresponds to the product one thinks it does, or that the \s-1ISMN\s0 corresponds to any product at all. It only produces a string that passes the checksum routine. If the \s-1ISMN\s0 passed to the constructor was invalid, the error might have been in any of the other nine positions. Converts the \s-1ISMN\s0 to the equivalent \s-1EAN\s0 (European Article Number). No pricing extension is added. Returns the \s-1EAN\s0 as a string. This method can also be used as an exportable function since it checks its argument list to determine what to do.

png_barcode()

Creates a \s-1PNG\s0 image of the \s-1EAN13\s0 barcode which corresponds to the \s-1ISMN\s0. Returns the image as a string.

\s-1EXPORTABLE\s0 \s-1FUNCTIONS\s0

Some functions can be used without the object interface. These do not use object technology behind the scenes.

is_valid_checksum('M021765430')

Takes the \s-1ISMN\s0 string and runs it through the checksum comparison routine. Returns \*(C`Business::ISMN::GOOD_ISMN\*(C' if the \s-1ISMN\s0 is valid, \*(C`Business::ISMN::BAD_CHECKSUM\*(C' if the string looks like an \s-1ISMN\s0 but has an invalid checksum, and \*(C`Business::ISMN::BAD_ISMN\*(C' if the string does not look like an \s-1ISMN\s0.

ismn_to_ean('M021765430')

Takes the \s-1ISMN\s0 string and converts it to the equivalent \s-1EAN\s0 string. This function checks for a valid \s-1ISMN\s0 and will return undef for invalid ISMNs, otherwise it returns the \s-1EAN\s0 as a string. Uses as_ean internally, which checks its arguments to determine what to do.

ean_to_ismn('9790021765439')

Takes the \s-1EAN\s0 string and converts it to the equivalent \s-1ISMN\s0 string. This function checks for a valid \s-1ISMN\s0 and will return undef for invalid ISMNs, otherwise it returns the \s-1EAN\s0 as a string. Uses as_ean internally, which checks its arguments to determine what to do.

TO DO

* i need more \s-1ISMN\s0 numbers for tests

SOURCE AVAILABILITY

This source is part of a SourceForge project which always has the latest sources in \s-1CVS\s0, as well as all of the previous releases.

http://sourceforge.net/projects/brian-d-foy/

If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately.

AUTHOR

brian d foy, \*(C`<[email protected]>\*(C'

COPYRIGHT AND LICENSE

Copyright (c) 2001-2007, brian d foy, All Rights Reserved.

You may redistribute this under the same terms as Perl itself.