Filename | /usr/share/perl5/Business/ISBN10.pm |
Statements | Executed 21 statements in 599µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 23µs | 31µs | BEGIN@4 | Business::ISBN10::
1 | 1 | 1 | 17µs | 333µs | BEGIN@7 | Business::ISBN10::
1 | 1 | 1 | 14µs | 43µs | BEGIN@9 | Business::ISBN10::
1 | 1 | 1 | 13µs | 140µs | BEGIN@5 | Business::ISBN10::
1 | 1 | 1 | 13µs | 73µs | BEGIN@25 | Business::ISBN10::
1 | 1 | 1 | 12µs | 81µ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 | 36µs | 2 | 39µs | # spent 31µs (23+8) within Business::ISBN10::BEGIN@4 which was called:
# once (23µs+8µs) by Business::ISBN::BEGIN@132 at line 4 # spent 31µs making 1 call to Business::ISBN10::BEGIN@4
# spent 8µs making 1 call to strict::import |
5 | 3 | 43µs | 2 | 267µs | # spent 140µs (13+127) within Business::ISBN10::BEGIN@5 which was called:
# once (13µs+127µs) by Business::ISBN::BEGIN@132 at line 5 # spent 140µs making 1 call to Business::ISBN10::BEGIN@5
# spent 127µs making 1 call to base::import |
6 | |||||
7 | 3 | 50µs | 2 | 649µs | # spent 333µs (17+316) within Business::ISBN10::BEGIN@7 which was called:
# once (17µs+316µs) by Business::ISBN::BEGIN@132 at line 7 # spent 333µs making 1 call to Business::ISBN10::BEGIN@7
# spent 316µs making 1 call to Exporter::import |
8 | |||||
9 | 1 | 8µs | 1 | 29µs | # spent 43µs (14+29) within Business::ISBN10::BEGIN@9 which was called:
# once (14µs+29µs) by Business::ISBN::BEGIN@132 at line 16 # spent 29µ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 | 35µs | 1 | 43µs | ); # spent 43µs making 1 call to Business::ISBN10::BEGIN@9 |
17 | |||||
18 | 1 | 8µs | 1 | 69µs | # spent 81µs (12+69) within Business::ISBN10::BEGIN@18 which was called:
# once (12µs+69µs) by Business::ISBN::BEGIN@132 at line 23 # spent 69µs making 1 call to vars::import |
19 | $VERSION | ||||
20 | $debug | ||||
21 | $MAX_GROUP_CODE_LENGTH | ||||
22 | %ERROR_TEXT | ||||
23 | 2 | 30µs | 1 | 81µs | ); # spent 81µs making 1 call to Business::ISBN10::BEGIN@18 |
24 | |||||
25 | 3 | 384µs | 2 | 132µs | # spent 73µs (13+59) within Business::ISBN10::BEGIN@25 which was called:
# once (13µs+59µs) by Business::ISBN::BEGIN@132 at line 25 # spent 73µs making 1 call to Business::ISBN10::BEGIN@25
# spent 59µs making 1 call to Exporter::import |
26 | |||||
27 | 1 | 600ns | my $debug = 0; | ||
28 | |||||
29 | 1 | 500ns | $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 | 4µs | 1; | ||
96 | |||||
97 | __END__ |