File Coverage

blib/lib/Business/ISBN10.pm
Criterion Covered Total %
statement 40 40 100.0
branch 5 6 83.3
condition n/a
subroutine 14 14 100.0
pod 2 2 100.0
total 61 62 98.3


line stmt bran cond sub pod time code
1 12     12   176 use 5.008;
  12         53  
2              
3             package Business::ISBN10;
4 12     12   52 use strict;
  12         16  
  12         274  
5 12     12   57 use base qw(Business::ISBN);
  12         17  
  12         1591  
6              
7 12     12   59 use Business::ISBN qw(:all);
  12         17  
  12         2179  
8              
9 12         543 use vars qw(
10             $MAX_GROUP_CODE_LENGTH
11             %ERROR_TEXT
12 12     12   65 );
  12         18  
13              
14 12     12   51 use Carp qw(carp croak cluck);
  12         18  
  12         4312  
15              
16             my $debug = 0;
17              
18             our $VERSION = '3.015_02';
19              
20 213301     213301   379924 sub _max_length { 10 }
21              
22 213305     213305   373881 sub _set_type { $_[0]->{type} = 'ISBN10' }
23              
24 213305     213305   352044 sub _parse_prefix { '' }
25             sub _set_prefix {
26 213306 100   213306   328528 croak "Cannot set prefix [$_[1]] on an ISBN-10" if length $_[1];
27              
28 213305         577016 $_[0]->{prefix} = $_[1];
29             }
30              
31             sub _hyphen_positions {
32             [
33 3     3   16 $_[0]->_group_code_length,
34             $_[0]->_group_code_length + $_[0]->_publisher_code_length,
35             9
36             ]
37             }
38              
39             sub as_isbn10 {
40 1     1 1 695 my $self = shift;
41              
42 1         4 my $isbn10 = Business::ISBN->new( $self->isbn );
43 1         6 $isbn10->fix_checksum;
44              
45 1         2 return $isbn10;
46             }
47              
48             sub as_isbn13 {
49 2     2 1 1559 my $self = shift;
50              
51 2         9 my $isbn13 = Business::ISBN->new( '978' . $self->isbn );
52 2         10 $isbn13->fix_checksum;
53              
54 2         6 return $isbn13;
55             }
56              
57             #internal function. you don't get to use this one.
58             sub _checksum {
59 213309     213309   375321 my $data = $_[0]->isbn;
60              
61 213309 50       352008 return unless defined $data;
62              
63 213309         573074 my @digits = split //, $data;
64 213309         237123 my $sum = 0;
65              
66 213309         329848 foreach( reverse 2..10 ) {
67 1919781         2662836 $sum += $_ * (shift @digits);
68             }
69              
70             #return what the check digit should be
71 213309         316407 my $checksum = (11 - ($sum % 11))%11;
72              
73 213309 100       342239 $checksum = 'X' if $checksum == 10;
74              
75 213309         861686 return $checksum;
76             }
77              
78              
79             1;
80              
81             __END__