Business-ISSN-0.91/0000755000076500007650000000000011046305555012776 5ustar brianbrianBusiness-ISSN-0.91/Changes0000644000076500007650000000033411046305555014271 0ustar brianbrianRevision history for Perl extension Business::ISSN. 0.91 - Wed Aug 6 06:30:10 2008 * module now maintained by brian d foy * modernized, fully tested, and fixed RT #38174 0.20 Tue Feb 9 11:09:41 1999 - 1st versionBusiness-ISSN-0.91/examples/0000755000076500007650000000000011046305555014614 5ustar brianbrianBusiness-ISSN-0.91/examples/placeholder.pl0000644000076500007650000000013011046305555017425 0ustar brianbrian#!/usr/bin/perl # See the module synopsis until I can create some interesting examples Business-ISSN-0.91/lib/0000755000076500007650000000000011046305555013544 5ustar brianbrianBusiness-ISSN-0.91/lib/ISSN.pm0000644000076500007650000001203111046305555014653 0ustar brianbrianpackage Business::ISSN; use strict; use warnings; no warnings; use subs qw(_common_format _checksum is_valid_checksum); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(is_valid_checksum); $VERSION = '0.91'; sub new { my $class = shift; my $common_data = _common_format shift; return unless $common_data; my $self = bless {}, $class; $self->{'issn'} = $common_data; $common_data =~m/(\d{7,7})([\dxX])$/; @{$self}{ qw(checksum code) } = ( $2, $1 ); $self->_check_validity; return $self; } sub _issn { $_[0]->{'issn'} } sub is_valid { $_[0]->{'valid'} } sub checksum { $_[0]->{'checksum'} } sub _hyphen_positions { 4 } sub fix_checksum { my $self = shift; my $debug = 1; my $last_char = substr($self->_issn, -1, 1); my $checksum = _checksum $self->_issn; substr( $self->{issn}, -1, 1) = $checksum; $self->_check_validity; return 0 if $last_char eq $checksum; return 1; } sub as_string { return unless $_[0]->is_valid; my $issn = $_[0]->_issn; substr($issn, $_[0]->_hyphen_positions, 0) = '-'; return $issn; } sub is_valid_checksum { my $data = _common_format shift; return 0 unless $data; return 1 if substr($data, -1, 1) eq _checksum $data; return 0; } sub _check_validity { $_[0]->{'valid'} = is_valid_checksum( $_[0]->_issn ); } sub _checksum { my $data = _common_format shift; return unless $data; my @digits = split //, $data; my $sum = 0; foreach( reverse 2..8 ) # oli 10 { $sum += $_ * (shift @digits); } #return what the check digit should be my $checksum = (11 - ($sum % 11))%11; $checksum = 'X' if $checksum == 10; return $checksum; } sub _common_format { #we want uppercase X's my $data = uc shift; #get rid of everything except decimal digits and X $data =~ s/[^0-9X]//g; return $data if $data =~ m/^\d{7}[0-9X]\z/; return; } 1; __END__ =head1 NAME Business::ISSN - Perl extension for International Standard Serial Numbers =head1 SYNOPSIS use Business::ISSN; $issn_object = Business::ISSN->new('1456-5935'); $issn_object = Business::ISSN->new('14565935'); # print the ISSN (with hyphen) print $issn_object->as_string; # check to see if the ISSN is valid $issn_object->is_valid; #fix the ISSN checksum. BEWARE: the error might not be #in the checksum! $issn_object->fix_checksum; #EXPORTABLE FUNCTIONS use Business::ISSN qw( is_valid_checksum ); #verify the checksum if( is_valid_checksum('01234567') ) { ... } =head1 DESCRIPTION =over 4 =item new($issn) The constructor accepts a scalar representing the ISSN. The string representing the ISSN may contain characters other than [0-9xX], although these will be removed in the internal representation. The resulting string must look like an ISSN - the first seven characters must be digits and the eighth character must be a digit, 'x', or 'X'. The string passed as the ISSN need not be a valid ISSN as long as it superficially looks like one. This allows one to use the C method. One should check the validity of the ISSN with C rather than relying on the return value of the constructor. If all one wants to do is check the validity of an ISSN, one can skip the object-oriented interface and use the c function which is exportable on demand. If the constructor decides it can't create an object, it returns undef. It may do this if the string passed as the ISSN can't be munged to the internal format. =item $obj->checksum Return the ISSN checksum. =item $obj->as_string Return the ISSN as a string. A terminating 'x' is changed to 'X'. =item $obj->is_valid Returns 1 if the checksum is valid. Returns 0 if the ISSN does not pass the checksum test. The constructor accepts invalid ISSN's so that they might be fixed with C. =item $obj->fix_checksum Replace the eighth character with the checksum the corresponds to the previous seven digits. This does not guarantee that the ISSN corresponds to the product one thinks it does, or that the ISSN corresponds to any product at all. It only produces a string that passes the checksum routine. If the ISSN passed to the constructor was invalid, the error might have been in any of the other nine positions. =back =head2 EXPORTABLE FUNCTIONS Some functions can be used without the object interface. These do not use object technology behind the scenes. =over 4 =item is_valid_checksum('01234567') Takes the ISSN string and runs it through the checksum comparison routine. Returns 1 if the ISSN is valid, 0 otherwise. =back =head1 AUTHOR Currently maintained by brian d foy C<< >>. Sami Poikonen Original module by Sami Poikonen, based on Business::ISBN by brian d foy. This module is released under the terms of the Perl Artistic License. =head1 COPYRIGHT AND LICENSE Copyright (c) 1999-2008, brian d foy, All Rights Reserved. You may redistribute this under the same terms as Perl itself. =cut Business-ISSN-0.91/LICENSE0000644000076500007650000000007711046305555014007 0ustar brianbrianYou can use Business::ISSN under the same terms as Perl itself.Business-ISSN-0.91/Makefile.PL0000644000076500007650000000121011046305555014742 0ustar brianbrian# $Id: Makefile.PL,v 1.4 2004/07/04 17:04:17 comdog Exp $ use ExtUtils::MakeMaker; require 5.006; eval "use Test::Manifest 1.14"; WriteMakefile( 'NAME' => 'Business::ISSN', 'ABSTRACT' => 'Work with International Standard Serial Numbers', 'VERSION_FROM' => 'lib/ISSN.pm', 'LICENSE' => 'perl', 'AUTHOR' => 'brian d foy ', 'PREREQ_PM' => { 'Test::More' => '0', }, 'PM' => { 'lib/ISSN.pm' => '$(INST_LIBDIR)/ISSN.pm', }, 'MAN3PODS' => { 'lib/ISSN.pm' => '$(INST_MAN3DIR)/Business-ISSN.3', }, clean => { FILES => q|Business-* cover_db *.old *.bak| }, ); Business-ISSN-0.91/MANIFEST0000644000076500007650000000037211046305555014131 0ustar brianbrianChanges examples/placeholder.pl lib/ISSN.pm LICENSE Makefile.PL MANIFEST This list of files README t/issn.t t/load.t t/pod.t t/pod_coverage.t t/prereq.t t/test_manifest META.yml Module meta-data (added by MakeMaker) Business-ISSN-0.91/META.yml0000664000076500007650000000071211046305555014251 0ustar brianbrian--- #YAML:1.0 name: Business-ISSN version: 0.91 abstract: Work with International Standard Serial Numbers license: perl author: - brian d foy generated_by: ExtUtils::MakeMaker version 6.44 distribution_type: module requires: Test::More: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Business-ISSN-0.91/README0000644000076500007650000000102211046305555013651 0ustar brianbrian$Id: README,v 1.1 2004/09/08 00:25:41 comdog Exp $ You can install this using in the usual Perl fashion perl Makefile.PL make make test make install The documentation is in the module file. Once you install the file, you can read it with perldoc. perldoc Business::ISSN If you want to read it before you install it, you can use perldoc directly on the module file. perldoc lib/ISSN.pm This module is also in CVS on SourceForge http://sourceforge.net/projects/brian-d-foy/ Enjoy, brian d foy, bdfoy@cpan.orgBusiness-ISSN-0.91/t/0000755000076500007650000000000011046305555013241 5ustar brianbrianBusiness-ISSN-0.91/t/issn.t0000755000076500007650000000344011046305555014406 0ustar brianbrian#!/usr/bin/perl use warnings; use strict; use Test::More 'no_plan'; my $class = 'Business::ISSN'; use_ok( $class, qw(is_valid_checksum) ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Things that should work { my @valid_issns = qw( 0355-4325 1553-667X ); foreach my $issn ( @valid_issns ) { my $obj = $class->new( $issn ); isa_ok( $obj, $class ); ok( $obj->is_valid, "ISSN $issn is valid" ); is( $obj->checksum, substr( $issn, -1, 1 ), "checksum returns right value" ); is( $obj->as_string, $issn, "as_string matches original" ); ok( is_valid_checksum( $issn ), "is_valid_checksum returns true for good issn" ); ok( ! $obj->fix_checksum, "fix_checksum returns false for good issn" ); } } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Things that shouldn't work at all { my @invalid_issns = qw( 0355-4323 abcd pwer-1234 ); foreach my $issn ( @invalid_issns ) { my $obj = $class->new( $issn ); ok( ! eval { $obj->is_valid }, "ISSN $issn is not valid" ); ok( ! is_valid_checksum( $issn ), "is_valid_checksum returns false for bad issn" ); } } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Things that we can fix { my @invalid_issns = ( [ qw( 0355-4323 0355-4325 ) ], [ qw( 1553-6673 1553-667X ) ], ); foreach my $pair ( @invalid_issns ) { my $obj = $class->new( $pair->[0] ); isa_ok( $obj, $class ); ok( ! eval { $obj->is_valid }, "ISSN $pair->[0] is not valid" ); ok( ! defined $obj->as_string, "as_string returns undef before we fix issn" ); ok( ! is_valid_checksum( $pair->[0] ), "is_valid_checksum returns false for fixable issn" ); ok( $obj->fix_checksum, "fix_checksum returns true" ); ok( $obj->is_valid, "ISSN $pair->[1] is now valid" ); is( $obj->as_string, $pair->[1], "as_string returns fixed issn" ); } }Business-ISSN-0.91/t/load.t0000644000076500007650000000036511046305555014351 0ustar brianbrian# $Id: load.t,v 1.2 2004/09/08 00:25:42 comdog Exp $ BEGIN { @classes = qw(Business::ISSN); } use Test::More tests => scalar @classes; foreach my $class ( @classes ) { print "Bail out! $class did not compile\n" unless use_ok( $class ); } Business-ISSN-0.91/t/pod.t0000644000076500007650000000021011046305555014201 0ustar brianbrian# $Id$ use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Business-ISSN-0.91/t/pod_coverage.t0000644000076500007650000000027711046305555016071 0ustar brianbrian# $Id$ use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Business-ISSN-0.91/t/prereq.t0000644000076500007650000000020211046305555014716 0ustar brianbrian# $Id$ use Test::More; eval "use Test::Prereq"; plan skip_all => "Test::Prereq required to test dependencies" if $@; prereq_ok(); Business-ISSN-0.91/t/test_manifest0000644000076500007650000000006311046305555016030 0ustar brianbrian# $Id$ load.t pod.t pod_coverage.t #prereq.t issn.t