Debian Codegraph @

t/rt/29292.t

raw
1 # $Revision: 1.1 $
2 use strict;
3
4 use Test::More 'no_plan';
5
6 use Business::ISBN qw(:all);
7
8 my @isbns = qw(
9 91-7119-704-4
10 978-91-7119-810-5
11 978-0-911910-00-1
12 978-0-88264-180-5
13 );
14
15 foreach my $isbn ( @isbns )
16 {
17 ( my $stripped = $isbn ) =~ s/-//g;
18
19 my $object = Business::ISBN->new( $stripped );
20 my $pretty = $object->as_string;
21
22 is( $pretty, $isbn, "[$isbn] comes out right" );
23 }
24
25
26
27
28 __END__
29 Hi Ed and Brian,
30
31 Is the following a known problem, and is there any fix?
32
33 I'm having great fun with the CPAN package Business::ISBN,
34 but it's odd that as_string() produces different results for
35 10-digit and 13-digit ISBNs.
36
37 For example, it correctly suggests 91-7119-704-4 but then wrongly
38 978-91-711-9810-5. In both cases, 91-7 should be followed by
39 three digits (91-7119-) before the next hyphen.
40
41 The file Business/ISBN/Data.pm correctly states:
42
43 91 => [ 'Sweden', [ '0' => 1, 20 => 49,
44 500 => 649, 7000 => 7999,
45 85000 => 94999, 970000 => 999999 ] ],
46
47 This works perfectly fine ISBN-10 and for 978-91-[0-6], but [789]
48 are followed by just two more digits (e.g. -711-) before the next
49 hyphen. It also wrongly suggests 978-0-8826-4180-5 (should be
50 0-88264-) and 978-0-9119-1000-1 (should be 0-911910-).
51
52 It is as if it never puts the middle hyphen after the 8:th digit,
53 which is a reasonable thing to do in an ISBN-10, but not in
54 ISBN-13. Maybe the Perldoc line "Positions less than 1 and
55 greater than 9 are silently ignored" for as_string() is the key to
56 the problem? When we're dealing with ISBN-13s, these positions
57 should be counted from the end of the string, not from the
58 beginning.
59
60 Here's my program:
61
62 #!/usr/bin/perl -w
63
64 use Business::ISBN;
65 use strict;
66
67 my $isbn = Business::ISBN->new("9789171198105");
68 my $pretty = $isbn->as_string;
69 print "$pretty\n";