pax_global_header00006660000000000000000000000064121001605630014504gustar00rootroot0000000000000052 comment=7b01c53dfce421771112af6ed95c7464bee1a933 Business-ISSN-0.91/000075500000000000000000000000001210016056300140005ustar00rootroot00000000000000Business-ISSN-0.91/.gear/000075500000000000000000000000001210016056300147745ustar00rootroot00000000000000Business-ISSN-0.91/.gear/rules000064400000000000000000000000441210016056300160470ustar00rootroot00000000000000tar: . name=Business-ISSN-@version@ Business-ISSN-0.91/Changes000064400000000000000000000003341210016056300152730ustar00rootroot00000000000000Revision 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/LICENSE000064400000000000000000000000771210016056300150110ustar00rootroot00000000000000You can use Business::ISSN under the same terms as Perl itself.Business-ISSN-0.91/MANIFEST000064400000000000000000000003721210016056300151330ustar00rootroot00000000000000Changes 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.yml000064400000000000000000000007121210016056300152510ustar00rootroot00000000000000--- #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/Makefile.PL000064400000000000000000000012101210016056300157440ustar00rootroot00000000000000# $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/README000064400000000000000000000010221210016056300146530ustar00rootroot00000000000000$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/examples/000075500000000000000000000000001210016056300156165ustar00rootroot00000000000000Business-ISSN-0.91/examples/placeholder.pl000064400000000000000000000001301210016056300204270ustar00rootroot00000000000000#!/usr/bin/perl # See the module synopsis until I can create some interesting examples Business-ISSN-0.91/lib/000075500000000000000000000000001210016056300145465ustar00rootroot00000000000000Business-ISSN-0.91/lib/ISSN.pm000064400000000000000000000120311210016056300156550ustar00rootroot00000000000000package 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/perl-Business-ISSN.spec000064400000000000000000000053421210016056300201650ustar00rootroot00000000000000# # - Business::ISSN - # This spec file was automatically generated by cpan2rpm [ver: 2.028] # (ALT Linux revision) # The following arguments were used: # -f pl # For more information on cpan2rpm please visit: http://perl.arix.com/ # %define module Business-ISSN %define m_distro Business-ISSN %define m_name Business::ISSN %define m_author_id unknown %define _enable_test 1 Name: perl-Business-ISSN Version: 0.91 Release: alt1 Summary: Work with International Standard Serial Numbers License: Artistic Group: Development/Perl Url: http://www.cpan.org Packager: Kirill Maslinsky BuildArch: noarch Source: http://search.cpan.org//CPAN/authors/id/B/BD/BDFOY/%m_distro-%version.tar BuildRequires: perl-Module-Build %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 `fix_checksum' method. One should check the validity of the ISSN 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 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 `fix_checksum'. =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 %prep %setup -n %m_distro-%version %build %perl_vendor_build %install %perl_vendor_install %files %perl_vendor_privlib/Business/* %changelog * Thu Jan 24 2013 Kirill Maslinsky 0.91-alt1 - initial build for ALT Linux Sisyphus Business-ISSN-0.91/t/000075500000000000000000000000001210016056300142435ustar00rootroot00000000000000Business-ISSN-0.91/t/issn.t000075500000000000000000000034401210016056300154100ustar00rootroot00000000000000#!/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.t000064400000000000000000000003651210016056300153530ustar00rootroot00000000000000# $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.t000064400000000000000000000002101210016056300152030ustar00rootroot00000000000000# $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.t000064400000000000000000000002771210016056300170730ustar00rootroot00000000000000# $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.t000064400000000000000000000002021210016056300157200ustar00rootroot00000000000000# $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_manifest000064400000000000000000000000631210016056300170320ustar00rootroot00000000000000# $Id$ load.t pod.t pod_coverage.t #prereq.t issn.t