1#!perl 2use v5.22; 3use feature qw(refaliasing signatures postderef); 4no warnings map { "experimental::$_" } qw(refaliasing signatures postderef); 5 6################################################################## 7# I added the error_text method in this version. You might have 8# to pull from GitHub to use the latest sources. 9# https://github.com/briandfoy/business-isbn 10use Business::ISBN '2.010_01'; 11 12################################################################## 13# https://bugs.launchpad.net/evergreen/+bug/1559281/comments/2 14# 15# This UbuntuOne thread has some example data for a publisher using 16# unassigned group codes. It does not note what the publisher code 17# ranges should be. 18my @tests = ( 19 [ qw(9786316294241 6316294247) ], # https://www.worldcat.org/title/black-mass/oclc/933728185 20 [ qw(9786316271976 6316271972) ], # DVD "Bridge of Spies" - https://www.worldcat.org/title/bridge-of-spies/oclc/933729520 21 [ qw(9786316364036) ], # DVD "Alvin and the Chipmunks. The road chip" - http://www.btol.com/home_whatshot_details.cfm?sideMenu=Featured%20CDs%20and%20DVDs&home=home_whatshot_details.cfm 22 [ qw(9786316334886) ], # DVD "Spectre" 23 [ qw(9786316321183) ], # DVD "Southerner" 24 [ qw(9786316319401) ], # DVD "Spotlight" 25 [ qw(9786316291431) ], # DVD "Steve Jobs" 26 ); 27 28################################################################## 29# This part tries the test cases with the official ISBN data 30# These should fail since the publisher is using unassigned group 31# codes, which are cleverly created in a way that an invalid 32# group code throws off the rest of the parsing. 33say "========= Before fake group insertion"; 34test_isbns( \@tests ); 35 36################################################################## 37# Now insert the fake group code by playing with the internal data 38# structure that you aren't supposed to know about. But, if you want 39# to use "bad" data, that's the trade-off 40say "========= After fake group insertion"; 41 42# the group code is a key in this hash. The first element of the 43# array ref is the label for the group code. The second argument is 44# another array ref that are the publisher code ranges. To see more, 45# look as Business::ISBN::Data's guts. The publisher ranges must be 46# strings so items such as "00" are correctly handled as something of 47# length 2. 48# 49# I don't know what Baker and Taylor are claiming to be the publishers. 50$Business::ISBN::country_data{ '631' } = [ 51 'Baker and Taylor', 52 [ '0' => '9' ], 53 ]; 54test_isbns( \@tests ); 55 56################################################################## 57# This sub goes through the array of arrays and makes an ISBN 58# object out of each thing. It's an array of arrays because I 59# kept together the ISBN-10 and ISBN-13 versions. 60# 61# I use three experimental Perl features here (if I'm going to spend 62# the time writing the example for you, I get to choose!), but it's 63# not much work to not use them. You get the idea of what this is 64# doing. 65sub test_isbns ( $tests ) { 66 foreach \my @test ( $tests->@* ) { 67 foreach my $test_isbn ( @test ) { 68 my $isbn = Business::ISBN->new( $test_isbn ); 69 if( $isbn->is_valid ) { 70 say "$test_isbn is valid"; 71 say "\tgroup -> ", $isbn->group_code; 72 say "\tpublisher -> ", $isbn->publisher_code; 73 say "\tarticle -> ", $isbn->article_code; 74 say "\tchecksum -> ", $isbn->checksum; 75 } 76 else { 77 printf qq(%s is not valid! Error is "%s"\n), 78 $test_isbn, $isbn->error_text; 79 } 80 } 81 } 82 } 83 84