| 1 | 8 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package Business::ISBN13; | ||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 8 | ▶ | use base qw(Business::ISBN); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 8 | ▶ | use Business::ISBN qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | ▶ | use Carp qw(carp croak cluck); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 8 | my $debug = 0; | |||||||||
| 13 | |||||||||||
| 14 | 8 | our $VERSION = '3.014'; | |||||||||
| 15 | |||||||||||
| 16 | 32 | ▶ | sub _max_length { 13 } | ||||||||
|
Subroutine
_max_length: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 35 | ▶ | sub _set_type { $_[0]->{type} = 'ISBN13' } | ||||||||
|
Subroutine
_set_type: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 35 | ▶ | sub _parse_prefix { | ||||||||
|
Subroutine
_parse_prefix: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 35 | my $isbn = $_[0]->isbn; # stupid workaround for 'Can't modify non-lvalue subroutine call' | |||||||||
| 22 | 35 | ( $isbn =~ /\A(97[89])(.{10})\z/g )[0]; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 36 | ▶ | sub _set_prefix { | ||||||||
|
Subroutine
_set_prefix: called CC=2 SCAR=6.9
| |||||||||||
| 26 | 36 | ▶ | croak "Cannot set prefix [$_[1]] on an ISBN-13" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | unless $_[1] =~ m/\A97[89]\z/; | ||||||||||
| 28 | |||||||||||
| 29 | 34 | $_[0]->{prefix} = $_[1]; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 9 | ▶ | sub _hyphen_positions { | ||||||||
|
Subroutine
_hyphen_positions: called CC=1 SCAR=0.0
| |||||||||||
| 33 | [ | ||||||||||
| 34 | 9 | $_[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 | 1 | ▶ | sub as_isbn10 { | ||||||||
|
Subroutine
as_isbn10: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 44 | 1 | my $self = shift; | |||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | return unless $self->prefix eq '978'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 1 | my $isbn10 = Business::ISBN->new( | |||||||||
| 49 | substr( $self->isbn, 3 ) | ||||||||||
| 50 | ); | ||||||||||
| 51 | 1 | $isbn10->fix_checksum; | |||||||||
| 52 | |||||||||||
| 53 | 1 | return $isbn10; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | sub as_isbn13 { | ||||||||
|
Subroutine
as_isbn13: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 1 | my $self = shift; | |||||||||
| 58 | |||||||||||
| 59 | 1 | my $isbn13 = Business::ISBN->new( $self->as_string ); | |||||||||
| 60 | 1 | $isbn13->fix_checksum; | |||||||||
| 61 | |||||||||||
| 62 | 1 | return $isbn13; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | #internal function. you don't get to use this one. | ||||||||||
| 66 | 53 | ▶ | sub _checksum { | ||||||||
|
Subroutine
_checksum: called CC=3 SCAR=11.0
| |||||||||||
| 67 | 53 | my $data = $_[0]->isbn; | |||||||||
| 68 | |||||||||||
| 69 | 53 | ▶ | return unless defined $data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 53 | my $sum = 0; | |||||||||
| 72 | |||||||||||
| 73 | 53 | foreach my $index ( 0, 2, 4, 6, 8, 10 ) | |||||||||
| 74 | { | ||||||||||
| 75 | 318 | $sum += substr($data, $index, 1); | |||||||||
| 76 | 318 | $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 | my $checksum = ( 10 * ( int( $sum / 10 ) + 1 ) - $sum ) % 10; | |||||||||
| 83 | |||||||||||
| 84 | 53 | return $checksum; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 8 | 1; | |||||||||
| 88 | |||||||||||
| 89 | __END__ | ||||||||||