line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
131
|
use 5.008; |
|
8
|
|
|
|
|
24
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Business::ISBN13; |
4
|
8
|
|
|
8
|
|
39
|
use strict; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
175
|
|
5
|
8
|
|
|
8
|
|
39
|
use base qw(Business::ISBN); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
716
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
52
|
use Business::ISBN qw(:all); |
|
8
|
|
|
|
|
25
|
|
|
8
|
|
|
|
|
948
|
|
8
|
8
|
|
|
8
|
|
4746
|
use Data::Dumper; |
|
8
|
|
|
|
|
58696
|
|
|
8
|
|
|
|
|
531
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
65
|
use Carp qw(carp croak cluck); |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
3929
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $debug = 0; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '3.008'; |
15
|
|
|
|
|
|
|
|
16
|
32
|
|
|
32
|
|
74
|
sub _max_length { 13 } |
17
|
|
|
|
|
|
|
|
18
|
35
|
|
|
35
|
|
87
|
sub _set_type { $_[0]->{type} = 'ISBN13' } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _parse_prefix { |
21
|
35
|
|
|
35
|
|
113
|
my $isbn = $_[0]->isbn; # stupid workaround for 'Can't modify non-lvalue subroutine call' |
22
|
35
|
|
|
|
|
182
|
( $isbn =~ /\A(97[89])(.{10})\z/g )[0]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _set_prefix { |
26
|
36
|
100
|
|
36
|
|
795
|
croak "Cannot set prefix [$_[1]] on an ISBN-13" |
27
|
|
|
|
|
|
|
unless $_[1] =~ m/\A97[89]\z/; |
28
|
|
|
|
|
|
|
|
29
|
34
|
|
|
|
|
106
|
$_[0]->{prefix} = $_[1]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _hyphen_positions { |
33
|
|
|
|
|
|
|
[ |
34
|
9
|
|
|
9
|
|
32
|
$_[0]->_prefix_length, |
35
|
|
|
|
|
|
|
$_[0]->_prefix_length + $_[0]->_group_code_length, |
36
|
|
|
|
|
|
|
$_[0]->_prefix_length + $_[0]->_group_code_length + $_[0]->_publisher_code_length, |
37
|
|
|
|
|
|
|
$_[0]->_checksum_pos, |
38
|
|
|
|
|
|
|
] |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# sub group { 'Bookland' } |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub as_isbn10 { |
44
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
1
|
50
|
|
|
|
3
|
return unless $self->prefix eq '978'; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
4
|
my $isbn10 = Business::ISBN->new( |
49
|
|
|
|
|
|
|
substr( $self->isbn, 3 ) |
50
|
|
|
|
|
|
|
); |
51
|
1
|
|
|
|
|
8
|
$isbn10->fix_checksum; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
2
|
return $isbn10; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub as_isbn13 { |
57
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
5
|
my $isbn13 = Business::ISBN->new( $self->as_string ); |
60
|
1
|
|
|
|
|
9
|
$isbn13->fix_checksum; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
2
|
return $isbn13; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#internal function. you don't get to use this one. |
66
|
|
|
|
|
|
|
sub _checksum { |
67
|
53
|
|
|
53
|
|
113
|
my $data = $_[0]->isbn; |
68
|
|
|
|
|
|
|
|
69
|
53
|
50
|
|
|
|
111
|
return unless defined $data; |
70
|
|
|
|
|
|
|
|
71
|
53
|
|
|
|
|
73
|
my $sum = 0; |
72
|
|
|
|
|
|
|
|
73
|
53
|
|
|
|
|
92
|
foreach my $index ( 0, 2, 4, 6, 8, 10 ) |
74
|
|
|
|
|
|
|
{ |
75
|
318
|
|
|
|
|
424
|
$sum += substr($data, $index, 1); |
76
|
318
|
|
|
|
|
536
|
$sum += 3 * substr($data, $index + 1, 1); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#take the next higher multiple of 10 and subtract the sum. |
80
|
|
|
|
|
|
|
#if $sum is 37, the next highest multiple of ten is 40. the |
81
|
|
|
|
|
|
|
#check digit would be 40 - 37 => 3. |
82
|
53
|
|
|
|
|
212
|
my $checksum = ( 10 * ( int( $sum / 10 ) + 1 ) - $sum ) % 10; |
83
|
|
|
|
|
|
|
|
84
|
53
|
|
|
|
|
223
|
return $checksum; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |