| Filename | /usr/share/perl5/Business/ISBN13.pm |
| Statements | Executed 24 statements in 730µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 17µs | 21µs | Business::ISBN13::BEGIN@4 |
| 1 | 1 | 1 | 15µs | 67µs | Business::ISBN13::BEGIN@23 |
| 1 | 1 | 1 | 14µs | 50µs | Business::ISBN13::BEGIN@8 |
| 1 | 1 | 1 | 11µs | 198µs | Business::ISBN13::BEGIN@7 |
| 1 | 1 | 1 | 10µs | 37µs | Business::ISBN13::BEGIN@10 |
| 1 | 1 | 1 | 10µs | 62µs | Business::ISBN13::BEGIN@5 |
| 1 | 1 | 1 | 9µs | 112µs | Business::ISBN13::BEGIN@18 |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::_checksum |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::_hyphen_positions |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::_max_length |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::_parse_prefix |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::_set_prefix |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::_set_type |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::as_isbn10 |
| 0 | 0 | 0 | 0s | 0s | Business::ISBN13::as_isbn13 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # $Revision: 2.8 $ | ||||
| 2 | # $Id: ISBN13.pm,v 2.8 2007/09/17 02:34:58 comdog Exp $ | ||||
| 3 | package Business::ISBN13; | ||||
| 4 | 3 | 35µs | 2 | 25µs | # spent 21µs (17+4) within Business::ISBN13::BEGIN@4 which was called:
# once (17µs+4µs) by Business::ISBN::BEGIN@133 at line 4 # spent 21µs making 1 call to Business::ISBN13::BEGIN@4
# spent 4µs making 1 call to strict::import |
| 5 | 3 | 35µs | 2 | 114µs | # spent 62µs (10+52) within Business::ISBN13::BEGIN@5 which was called:
# once (10µs+52µs) by Business::ISBN::BEGIN@133 at line 5 # spent 62µs making 1 call to Business::ISBN13::BEGIN@5
# spent 52µs making 1 call to base::import |
| 6 | |||||
| 7 | 3 | 36µs | 2 | 386µs | # spent 198µs (11+188) within Business::ISBN13::BEGIN@7 which was called:
# once (11µs+188µs) by Business::ISBN::BEGIN@133 at line 7 # spent 198µs making 1 call to Business::ISBN13::BEGIN@7
# spent 187µs making 1 call to Exporter::import |
| 8 | 3 | 42µs | 2 | 87µs | # spent 50µs (14+37) within Business::ISBN13::BEGIN@8 which was called:
# once (14µs+37µs) by Business::ISBN::BEGIN@133 at line 8 # spent 50µs making 1 call to Business::ISBN13::BEGIN@8
# spent 37µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 26µs | # spent 37µs (10+26) within Business::ISBN13::BEGIN@10 which was called:
# once (10µs+26µs) by Business::ISBN::BEGIN@133 at line 17 # spent 26µs making 1 call to subs::import | ||
| 11 | _checksum | ||||
| 12 | INVALID_COUNTRY_CODE | ||||
| 13 | INVALID_PUBLISHER_CODE | ||||
| 14 | BAD_CHECKSUM | ||||
| 15 | GOOD_ISBN | ||||
| 16 | BAD_ISBN | ||||
| 17 | 3 | 28µs | 1 | 37µs | ); # spent 37µs making 1 call to Business::ISBN13::BEGIN@10 |
| 18 | 1 | 103µs | # spent 112µs (9+103) within Business::ISBN13::BEGIN@18 which was called:
# once (9µs+103µs) by Business::ISBN::BEGIN@133 at line 21 # spent 103µs making 1 call to vars::import | ||
| 19 | $VERSION | ||||
| 20 | $debug | ||||
| 21 | 3 | 53µs | 1 | 112µs | ); # spent 112µs making 1 call to Business::ISBN13::BEGIN@18 |
| 22 | |||||
| 23 | 3 | 495µs | 2 | 119µs | # spent 67µs (15+52) within Business::ISBN13::BEGIN@23 which was called:
# once (15µs+52µs) by Business::ISBN::BEGIN@133 at line 23 # spent 67µs making 1 call to Business::ISBN13::BEGIN@23
# spent 52µs making 1 call to Exporter::import |
| 24 | |||||
| 25 | 1 | 700ns | my $debug = 0; | ||
| 26 | |||||
| 27 | 1 | 500ns | $VERSION = '2.05'; | ||
| 28 | |||||
| 29 | sub _max_length { 13 } | ||||
| 30 | |||||
| 31 | sub _set_type { $_[0]->{type} = 'ISBN13' } | ||||
| 32 | |||||
| 33 | sub _parse_prefix | ||||
| 34 | { | ||||
| 35 | my $isbn = $_[0]->isbn; # stupid workaround for 'Can't modify non-lvalue subroutine call' | ||||
| 36 | ( $isbn =~ /\A(97[89])(.{10})\z/g )[0]; | ||||
| 37 | } | ||||
| 38 | |||||
| 39 | sub _set_prefix | ||||
| 40 | { | ||||
| 41 | croak "Cannot set prefix [$_[1]] on an ISBN-13" | ||||
| 42 | unless $_[1] =~ m/\A97[89]\z/; | ||||
| 43 | |||||
| 44 | $_[0]->{prefix} = $_[1]; | ||||
| 45 | } | ||||
| 46 | |||||
| 47 | sub _hyphen_positions | ||||
| 48 | { | ||||
| 49 | [ | ||||
| 50 | $_[0]->_prefix_length, | ||||
| 51 | $_[0]->_prefix_length + $_[0]->_group_code_length, | ||||
| 52 | $_[0]->_prefix_length + $_[0]->_group_code_length + $_[0]->_publisher_code_length, | ||||
| 53 | $_[0]->_checksum_pos, | ||||
| 54 | ] | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | # sub group { 'Bookland' } | ||||
| 58 | |||||
| 59 | sub as_isbn10 | ||||
| 60 | { | ||||
| 61 | my $self = shift; | ||||
| 62 | |||||
| 63 | return unless $self->prefix eq '978'; | ||||
| 64 | |||||
| 65 | my $isbn10 = Business::ISBN->new( | ||||
| 66 | substr( $self->isbn, 3 ) | ||||
| 67 | ); | ||||
| 68 | $isbn10->fix_checksum; | ||||
| 69 | |||||
| 70 | return $isbn10; | ||||
| 71 | } | ||||
| 72 | |||||
| 73 | sub as_isbn13 | ||||
| 74 | { | ||||
| 75 | my $self = shift; | ||||
| 76 | |||||
| 77 | my $isbn13 = Business::ISBN->new( $self->as_string ); | ||||
| 78 | $isbn13->fix_checksum; | ||||
| 79 | |||||
| 80 | return $isbn13; | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | #internal function. you don't get to use this one. | ||||
| 84 | sub _checksum | ||||
| 85 | { | ||||
| 86 | my $data = $_[0]->isbn; | ||||
| 87 | |||||
| 88 | return unless defined $data; | ||||
| 89 | |||||
| 90 | my @digits = split //, $data; | ||||
| 91 | my $sum = 0; | ||||
| 92 | |||||
| 93 | foreach my $index ( 0, 2, 4, 6, 8, 10 ) | ||||
| 94 | { | ||||
| 95 | $sum += substr($data, $index, 1); | ||||
| 96 | $sum += 3 * substr($data, $index + 1, 1); | ||||
| 97 | } | ||||
| 98 | |||||
| 99 | #take the next higher multiple of 10 and subtract the sum. | ||||
| 100 | #if $sum is 37, the next highest multiple of ten is 40. the | ||||
| 101 | #check digit would be 40 - 37 => 3. | ||||
| 102 | my $checksum = ( 10 * ( int( $sum / 10 ) + 1 ) - $sum ) % 10; | ||||
| 103 | |||||
| 104 | return $checksum; | ||||
| 105 | } | ||||
| 106 | |||||
| 107 | |||||
| 108 | 1 | 4µs | 1; | ||
| 109 | |||||
| 110 | __END__ |