| 1 | 8 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package Business::ISBN10; | ||||||||||
| 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 | |||||||||||
| 9 | 8 | ▶ | use vars qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | $MAX_GROUP_CODE_LENGTH | ||||||||||
| 11 | %ERROR_TEXT | ||||||||||
| 12 | 8 | ); | |||||||||
| 13 | |||||||||||
| 14 | 8 | ▶ | use Carp qw(carp croak cluck); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 8 | my $debug = 0; | |||||||||
| 17 | |||||||||||
| 18 | 8 | our $VERSION = '3.014'; | |||||||||
| 19 | |||||||||||
| 20 | 106641 | ▶ | sub _max_length { 10 } | ||||||||
|
Subroutine
_max_length: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 106643 | ▶ | sub _set_type { $_[0]->{type} = 'ISBN10' } | ||||||||
|
Subroutine
_set_type: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 106643 | ▶ | sub _parse_prefix { '' } | ||||||||
|
Subroutine
_parse_prefix: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 106644 | ▶ | sub _set_prefix { | ||||||||
|
Subroutine
_set_prefix: called CC=2 SCAR=6.9
| |||||||||||
| 26 | 106644 | ▶ | croak "Cannot set prefix [$_[1]] on an ISBN-10" if length $_[1]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 106643 | $_[0]->{prefix} = $_[1]; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 3 | ▶ | sub _hyphen_positions { | ||||||||
|
Subroutine
_hyphen_positions: called CC=1 SCAR=0.0
| |||||||||||
| 32 | [ | ||||||||||
| 33 | 3 | $_[0]->_group_code_length, | |||||||||
| 34 | $_[0]->_group_code_length + $_[0]->_publisher_code_length, | ||||||||||
| 35 | 9 | ||||||||||
| 36 | ] | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | ▶ | sub as_isbn10 { | ||||||||
|
Subroutine
as_isbn10: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | 1 | my $self = shift; | |||||||||
| 41 | |||||||||||
| 42 | 1 | my $isbn10 = Business::ISBN->new( $self->isbn ); | |||||||||
| 43 | 1 | $isbn10->fix_checksum; | |||||||||
| 44 | |||||||||||
| 45 | 1 | return $isbn10; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | ▶ | sub as_isbn13 { | ||||||||
|
Subroutine
as_isbn13: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 2 | my $self = shift; | |||||||||
| 50 | |||||||||||
| 51 | 2 | my $isbn13 = Business::ISBN->new( '978' . $self->isbn ); | |||||||||
| 52 | 2 | $isbn13->fix_checksum; | |||||||||
| 53 | |||||||||||
| 54 | 2 | return $isbn13; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | #internal function. you don't get to use this one. | ||||||||||
| 58 | 106649 | ▶ | sub _checksum { | ||||||||
|
Subroutine
_checksum: called CC=4 SCAR=13.9
| |||||||||||
| 59 | 106649 | my $data = $_[0]->isbn; | |||||||||
| 60 | |||||||||||
| 61 | 106649 | ▶ | return unless defined $data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 106649 | my @digits = split //, $data; | |||||||||
| 64 | 106649 | my $sum = 0; | |||||||||
| 65 | |||||||||||
| 66 | 106649 | foreach( reverse 2..10 ) { | |||||||||
| 67 | 959841 | $sum += $_ * (shift @digits); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | #return what the check digit should be | ||||||||||
| 71 | 106649 | my $checksum = (11 - ($sum % 11))%11; | |||||||||
| 72 | |||||||||||
| 73 | 106649 | ▶ | $checksum = 'X' if $checksum == 10; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | 106649 | return $checksum; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | 8 | 1; | |||||||||
| 80 | |||||||||||
| 81 | __END__ | ||||||||||