Filename | /usr/share/perl5/Business/ISBN10.pm |
Statements | Executed 21 statements in 732µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 32µs | 39µs | BEGIN@4 | Business::ISBN10::
1 | 1 | 1 | 21µs | 154µs | BEGIN@5 | Business::ISBN10::
1 | 1 | 1 | 21µs | 383µs | BEGIN@7 | Business::ISBN10::
1 | 1 | 1 | 13µs | 40µs | BEGIN@9 | Business::ISBN10::
1 | 1 | 1 | 12µs | 60µs | BEGIN@25 | Business::ISBN10::
1 | 1 | 1 | 10µs | 70µs | BEGIN@18 | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | _checksum | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | _hyphen_positions | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | _max_length | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | _parse_prefix | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | _set_prefix | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | _set_type | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | as_isbn10 | Business::ISBN10::
0 | 0 | 0 | 0s | 0s | as_isbn13 | Business::ISBN10::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Revision: 2.4 $ | ||||
2 | # $Id: ISBN10.pm,v 2.4 2007/08/13 03:15:22 comdog Exp $ | ||||
3 | package Business::ISBN10; | ||||
4 | 3 | 62µs | 2 | 47µs | # spent 39µs (32+8) within Business::ISBN10::BEGIN@4 which was called:
# once (32µs+8µs) by Business::ISBN::BEGIN@132 at line 4 # spent 39µs making 1 call to Business::ISBN10::BEGIN@4
# spent 8µs making 1 call to strict::import |
5 | 3 | 66µs | 2 | 287µs | # spent 154µs (21+133) within Business::ISBN10::BEGIN@5 which was called:
# once (21µs+133µs) by Business::ISBN::BEGIN@132 at line 5 # spent 154µs making 1 call to Business::ISBN10::BEGIN@5
# spent 133µs making 1 call to base::import |
6 | |||||
7 | 3 | 50µs | 2 | 746µs | # spent 383µs (21+363) within Business::ISBN10::BEGIN@7 which was called:
# once (21µs+363µs) by Business::ISBN::BEGIN@132 at line 7 # spent 383µs making 1 call to Business::ISBN10::BEGIN@7
# spent 363µs making 1 call to Exporter::import |
8 | |||||
9 | 1 | 7µs | 1 | 27µs | # spent 40µs (13+27) within Business::ISBN10::BEGIN@9 which was called:
# once (13µs+27µs) by Business::ISBN::BEGIN@132 at line 16 # spent 27µs making 1 call to subs::import |
10 | _checksum | ||||
11 | INVALID_GROUP_CODE | ||||
12 | INVALID_PUBLISHER_CODE | ||||
13 | BAD_CHECKSUM | ||||
14 | GOOD_ISBN | ||||
15 | BAD_ISBN | ||||
16 | 2 | 27µs | 1 | 40µs | ); # spent 40µs making 1 call to Business::ISBN10::BEGIN@9 |
17 | |||||
18 | 1 | 6µs | 1 | 60µs | # spent 70µs (10+60) within Business::ISBN10::BEGIN@18 which was called:
# once (10µs+60µs) by Business::ISBN::BEGIN@132 at line 23 # spent 60µs making 1 call to vars::import |
19 | $VERSION | ||||
20 | $debug | ||||
21 | $MAX_GROUP_CODE_LENGTH | ||||
22 | %ERROR_TEXT | ||||
23 | 2 | 29µs | 1 | 70µs | ); # spent 70µs making 1 call to Business::ISBN10::BEGIN@18 |
24 | |||||
25 | 3 | 477µs | 2 | 108µs | # spent 60µs (12+48) within Business::ISBN10::BEGIN@25 which was called:
# once (12µs+48µs) by Business::ISBN::BEGIN@132 at line 25 # spent 60µs making 1 call to Business::ISBN10::BEGIN@25
# spent 48µs making 1 call to Exporter::import |
26 | |||||
27 | 1 | 2µs | my $debug = 0; | ||
28 | |||||
29 | 1 | 1µs | $VERSION = '2.05'; | ||
30 | |||||
31 | sub _max_length { 10 } | ||||
32 | |||||
33 | sub _set_type { $_[0]->{type} = 'ISBN10' } | ||||
34 | |||||
35 | sub _parse_prefix { '' } | ||||
36 | sub _set_prefix | ||||
37 | { | ||||
38 | croak "Cannot set prefix [$_[1]] on an ISBN-10" if length $_[1]; | ||||
39 | |||||
40 | $_[0]->{prefix} = $_[1]; | ||||
41 | } | ||||
42 | |||||
43 | sub _hyphen_positions { | ||||
44 | [ | ||||
45 | $_[0]->_group_code_length, | ||||
46 | $_[0]->_group_code_length + $_[0]->_publisher_code_length, | ||||
47 | 9 | ||||
48 | ] | ||||
49 | } | ||||
50 | |||||
51 | sub as_isbn10 | ||||
52 | { | ||||
53 | my $self = shift; | ||||
54 | |||||
55 | my $isbn10 = Business::ISBN->new( $self->isbn ); | ||||
56 | $isbn10->fix_checksum; | ||||
57 | |||||
58 | return $isbn10; | ||||
59 | } | ||||
60 | |||||
61 | sub as_isbn13 | ||||
62 | { | ||||
63 | my $self = shift; | ||||
64 | |||||
65 | my $isbn13 = Business::ISBN->new( '978' . $self->isbn ); | ||||
66 | $isbn13->fix_checksum; | ||||
67 | |||||
68 | return $isbn13; | ||||
69 | } | ||||
70 | |||||
71 | #internal function. you don't get to use this one. | ||||
72 | sub _checksum | ||||
73 | { | ||||
74 | my $data = $_[0]->isbn; | ||||
75 | |||||
76 | return unless defined $data; | ||||
77 | |||||
78 | my @digits = split //, $data; | ||||
79 | my $sum = 0; | ||||
80 | |||||
81 | foreach( reverse 2..10 ) | ||||
82 | { | ||||
83 | $sum += $_ * (shift @digits); | ||||
84 | } | ||||
85 | |||||
86 | #return what the check digit should be | ||||
87 | my $checksum = (11 - ($sum % 11))%11; | ||||
88 | |||||
89 | $checksum = 'X' if $checksum == 10; | ||||
90 | |||||
91 | return $checksum; | ||||
92 | } | ||||
93 | |||||
94 | |||||
95 | 1 | 5µs | 1; | ||
96 | |||||
97 | __END__ |