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 8     8   146 use 5.008;
  8         29  
2              
3             package Business::ISBN10;
4 8     8   53 use strict;
  8         16  
  8         213  
5 8     8   40 use base qw(Business::ISBN);
  8         39  
  8         1089  
6              
7 8     8   53 use Business::ISBN qw(:all);
  8         19  
  8         1483  
8              
9 8         375 use vars qw(
10             $MAX_GROUP_CODE_LENGTH
11             %ERROR_TEXT
12 8     8   56 );
  8         88  
13              
14 8     8   45 use Carp qw(carp croak cluck);
  8         19  
  8         2986  
15              
16             my $debug = 0;
17              
18             our $VERSION = '3.008';
19              
20 106641     106641   228143 sub _max_length { 10 }
21              
22 106643     106643   227817 sub _set_type { $_[0]->{type} = 'ISBN10' }
23              
24 106643     106643   194950 sub _parse_prefix { '' }
25             sub _set_prefix {
26 106644 100   106644   208333 croak "Cannot set prefix [$_[1]] on an ISBN-10" if length $_[1];
27              
28 106643         265096 $_[0]->{prefix} = $_[1];
29             }
30              
31             sub _hyphen_positions {
32             [
33 3     3   11 $_[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 3 my $self = shift;
41              
42 1         3 my $isbn10 = Business::ISBN->new( $self->isbn );
43 1         13 $isbn10->fix_checksum;
44              
45 1         4 return $isbn10;
46             }
47              
48             sub as_isbn13 {
49 2     2 1 513 my $self = shift;
50              
51 2         6 my $isbn13 = Business::ISBN->new( '978' . $self->isbn );
52 2         8 $isbn13->fix_checksum;
53              
54 2         10 return $isbn13;
55             }
56              
57             #internal function. you don't get to use this one.
58             sub _checksum {
59 106649     106649   210639 my $data = $_[0]->isbn;
60              
61 106649 50       209887 return unless defined $data;
62              
63 106649         322571 my @digits = split //, $data;
64 106649         142470 my $sum = 0;
65              
66 106649         187274 foreach( reverse 2..10 ) {
67 959841         1541111 $sum += $_ * (shift @digits);
68             }
69              
70             #return what the check digit should be
71 106649         185605 my $checksum = (11 - ($sum % 11))%11;
72              
73 106649 100       187211 $checksum = 'X' if $checksum == 10;
74              
75 106649         470646 return $checksum;
76             }
77              
78              
79             1;
80              
81             __END__