.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Business::ISMN 3" .TH Business::ISMN 3 2024-02-17 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Business::ISMN \- work with International Standard Music Numbers .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Business::ISMN; \& \& $ismn_object = Business::ISMN\->new(\*(AqM021765430\*(Aq); \& $ismn_object = Business::ISMN\->new(\*(AqM\-021\-76543\-0\*(Aq); \& \& #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(\*(Aq0123456789\*(Aq) \& eq Business::ISMN::GOOD_ISMN ) \& { ... } \& \& #convert to EAN (European Article Number) \& $ean = ismn_to_ean(\*(Aq1565921496\*(Aq); \& \& #convert from EAN (European Article Number) \& $ismn = ean_to_ismn(\*(Aq9781565921498\*(Aq); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" .SS Methods .IX Subsection "Methods" .IP new($ismn) 4 .IX Item "new($ismn)" The constructor accepts a scalar representing the ISMN. .Sp The string representing the ISMN may contain characters other than \f(CW\*(C`[0\-9mM]\*(C'\fR, 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. .Sp The constructor attempts to determine the country code and the publisher code. If these data cannot be determined, the constructor sets \f(CW\*(C`$obj\->is_valid\*(C'\fR to something other than \f(CW\*(C`GOOD_ISMN\*(C'\fR. An object is still returned and it is up to the program to check \f(CW\*(C`$obj\->is_valid\*(C'\fR 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. .Sp .Vb 4 \& Business::ISMN::INVALID_PUBLISHER_CODE \& Business::ISMN::BAD_CHECKSUM \& Business::ISMN::GOOD_ISMN \& Business::ISMN::BAD_ISMN .Ve .Sp 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 \f(CWfix_checksum()\fR 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 \f(CWis_valid()\fR 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 \f(CWis_valid_checksum()\fR function which is exportable on demand. .Sp If the constructor decides it cannot create an object, it returns \f(CW\*(C`undef\*(C'\fR. 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. .IP ismn 4 .IX Item "ismn" Returns the ISMN as a string .IP country 4 .IX Item "country" .PD 0 .IP publisher 4 .IX Item "publisher" .PD Returns the country associated with the publisher code. This method was formerly called \f(CW\*(C`publisher\*(C'\fR (and that still works), but it's really returns a two letter country code. .IP publisher_code 4 .IX Item "publisher_code" Returns the publisher code or \f(CW\*(C`undef\*(C'\fR if no publisher code was found. .IP article_code 4 .IX Item "article_code" Returns the article code or \f(CW\*(C`undef\*(C'\fR if no article code was found. .IP checksum 4 .IX Item "checksum" Returns the checksum or \f(CW\*(C`undef\*(C'\fR if no publisher code was found. .IP hyphen_positions 4 .IX Item "hyphen_positions" Returns the list of hyphen positions as determined from the country and publisher codes. the \f(CW\*(C`as_string\*(C'\fR method provides a way to temporarily override these positions and to even forego them altogether. .IP "\fBas_string()\fR, as_string([])" 4 .IX Item "as_string(), as_string([])" Return the ISMN 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 ISMN based on the discovered publisher code. An ISMN that is not valid may produce strange results. .Sp 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. .IP is_valid 4 .IX Item "is_valid" Returns \f(CW\*(C`Business::ISMN::GOOD_ISMN\*(C'\fR if the checksum is valid and the country and publisher codes are defined. .Sp Returns \f(CW\*(C`Business::ISMN::BAD_CHECKSUM\*(C'\fR if the ISMN does not pass the checksum test. The constructor accepts invalid ISMN's so that they might be fixed with \f(CW\*(C`fix_checksum\*(C'\fR. .Sp Returns \f(CW\*(C`Business::ISMN::INVALID_PUBLISHER_CODE\*(C'\fR if a publisher code could not be determined. .Sp Returns \f(CW\*(C`Business::ISMN::BAD_ISMN\*(C'\fR if the string has no hope of ever looking like a valid ISMN. This might include strings such as \f(CW"abc"\fR, \&\f(CW"123456"\fR, and so on. .IP is_valid_country_code 4 .IX Item "is_valid_country_code" .PD 0 .IP is_valid_publisher_code 4 .IX Item "is_valid_publisher_code" .PD Returns true if the country code is valid, and false otherwise. .Sp This method was formerly called \f(CW\*(C`is_valid_publisher_code\*(C'\fR. That's deprecated but still there. .IP \fBfix_checksum()\fR 4 .IX Item "fix_checksum()" Replace the tenth character with the checksum the corresponds to the previous nine digits. This does not guarantee that the ISMN corresponds to the product one thinks it does, or that the ISMN corresponds to any product at all. It only produces a string that passes the checksum routine. If the ISMN passed to the constructor was invalid, the error might have been in any of the other nine positions. .ie n .IP $obj\->\fBas_ean()\fR 4 .el .IP \f(CW$obj\fR\->\fBas_ean()\fR 4 .IX Item "$obj->as_ean()" Converts the ISMN to the equivalent EAN (European Article Number). No pricing extension is added. Returns the EAN as a string. This method can also be used as an exportable function since it checks its argument list to determine what to do. .IP \fBpng_barcode()\fR 4 .IX Item "png_barcode()" Creates a PNG image of the EAN13 barcode which corresponds to the ISMN. Returns the image as a string. .SS "EXPORTABLE FUNCTIONS" .IX Subsection "EXPORTABLE FUNCTIONS" Some functions can be used without the object interface. These do not use object technology behind the scenes. .IP is_valid_checksum('M021765430') 4 .IX Item "is_valid_checksum('M021765430')" Takes the ISMN string and runs it through the checksum comparison routine. Returns \f(CW\*(C`Business::ISMN::GOOD_ISMN\*(C'\fR if the ISMN is valid, \f(CW\*(C`Business::ISMN::BAD_CHECKSUM\*(C'\fR if the string looks like an ISMN but has an invalid checksum, and \&\f(CW\*(C`Business::ISMN::BAD_ISMN\*(C'\fR if the string does not look like an ISMN. .IP ismn_to_ean('M021765430') 4 .IX Item "ismn_to_ean('M021765430')" Takes the ISMN string and converts it to the equivalent EAN string. This function checks for a valid ISMN and will return undef for invalid ISMNs, otherwise it returns the EAN as a string. Uses as_ean internally, which checks its arguments to determine what to do. .IP ean_to_ismn('9790021765439') 4 .IX Item "ean_to_ismn('9790021765439')" Takes the EAN string and converts it to the equivalent ISMN string. This function checks for a valid ISMN and will return undef for invalid ISMNs, otherwise it returns the EAN as a string. Uses as_ean internally, which checks its arguments to determine what to do. .SH "TO DO" .IX Header "TO DO" .IP \(bu 4 I need more ISMN numbers for tests .SH "SOURCE AVAILABILITY" .IX Header "SOURCE AVAILABILITY" This source is in Github: .PP .Vb 1 \& https://github.com/briandfoy/business\-ismn/ .Ve .SH AUTHOR .IX Header "AUTHOR" brian d foy, \f(CW\*(C`\*(C'\fR .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright © 2001\-2024, brian d foy . All rights reserved. .PP You may redistribute this under the terms of the Artistic License 2.0.