Filename | /usr/share/perl5/Business/ISBN13.pm |
Statements | Executed 24 statements in 669µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 18µs | 77µs | BEGIN@23 | Business::ISBN13::
1 | 1 | 1 | 16µs | 21µs | BEGIN@4 | Business::ISBN13::
1 | 1 | 1 | 15µs | 230µs | BEGIN@7 | Business::ISBN13::
1 | 1 | 1 | 13µs | 51µs | BEGIN@8 | Business::ISBN13::
1 | 1 | 1 | 11µs | 76µs | BEGIN@5 | Business::ISBN13::
1 | 1 | 1 | 10µs | 38µs | BEGIN@10 | Business::ISBN13::
1 | 1 | 1 | 10µs | 45µs | BEGIN@18 | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | _checksum | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | _hyphen_positions | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | _max_length | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | _parse_prefix | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | _set_prefix | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | _set_type | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | as_isbn10 | Business::ISBN13::
0 | 0 | 0 | 0s | 0s | as_isbn13 | Business::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 | 31µs | 2 | 26µs | # spent 21µs (16+5) within Business::ISBN13::BEGIN@4 which was called:
# once (16µs+5µs) by Business::ISBN::BEGIN@133 at line 4 # spent 21µs making 1 call to Business::ISBN13::BEGIN@4
# spent 5µs making 1 call to strict::import |
5 | 3 | 52µs | 2 | 140µs | # spent 76µs (11+64) within Business::ISBN13::BEGIN@5 which was called:
# once (11µs+64µs) by Business::ISBN::BEGIN@133 at line 5 # spent 76µs making 1 call to Business::ISBN13::BEGIN@5
# spent 64µs making 1 call to base::import |
6 | |||||
7 | 3 | 40µs | 2 | 445µs | # spent 230µs (15+215) within Business::ISBN13::BEGIN@7 which was called:
# once (15µs+215µs) by Business::ISBN::BEGIN@133 at line 7 # spent 230µs making 1 call to Business::ISBN13::BEGIN@7
# spent 215µs making 1 call to Exporter::import |
8 | 3 | 44µs | 2 | 89µs | # spent 51µs (13+38) within Business::ISBN13::BEGIN@8 which was called:
# once (13µs+38µs) by Business::ISBN::BEGIN@133 at line 8 # spent 51µs making 1 call to Business::ISBN13::BEGIN@8
# spent 38µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 28µs | # spent 38µs (10+28) within Business::ISBN13::BEGIN@10 which was called:
# once (10µs+28µs) by Business::ISBN::BEGIN@133 at line 17 # spent 28µ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 | 31µs | 1 | 38µs | ); # spent 38µs making 1 call to Business::ISBN13::BEGIN@10 |
18 | 1 | 36µs | # spent 45µs (10+36) within Business::ISBN13::BEGIN@18 which was called:
# once (10µs+36µs) by Business::ISBN::BEGIN@133 at line 21 # spent 36µs making 1 call to vars::import | ||
19 | $VERSION | ||||
20 | $debug | ||||
21 | 3 | 50µs | 1 | 45µs | ); # spent 45µs making 1 call to Business::ISBN13::BEGIN@18 |
22 | |||||
23 | 3 | 416µs | 2 | 136µs | # spent 77µs (18+59) within Business::ISBN13::BEGIN@23 which was called:
# once (18µs+59µs) by Business::ISBN::BEGIN@133 at line 23 # spent 77µs making 1 call to Business::ISBN13::BEGIN@23
# spent 59µs making 1 call to Exporter::import |
24 | |||||
25 | 1 | 800ns | my $debug = 0; | ||
26 | |||||
27 | 1 | 600ns | $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__ |