line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
23072
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
120
|
|
2
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
173
|
|
3
|
|
|
|
|
|
|
package SeeAlso::Identifier::ISBN; |
4
|
|
|
|
|
|
|
{ |
5
|
|
|
|
|
|
|
$SeeAlso::Identifier::ISBN::VERSION = '0.71'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
#ABSTRACT: International Standard Book Number as Identifier |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
2684
|
use Business::ISBN; |
|
3
|
|
|
|
|
158863
|
|
|
3
|
|
|
|
|
142
|
|
10
|
3
|
|
|
3
|
|
36
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
196
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
18
|
use base qw( SeeAlso::Identifier ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1788
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse { |
16
|
32
|
|
|
32
|
1
|
49
|
my $value = shift; |
17
|
32
|
50
|
100
|
|
|
91
|
$value = shift if ref($value) and scalar @_; |
18
|
|
|
|
|
|
|
|
19
|
32
|
100
|
100
|
|
|
232
|
if (defined $value and not UNIVERSAL::isa( $value, 'Business::ISBN' ) ) { |
20
|
25
|
|
|
|
|
60
|
$value =~ s/^urn:isbn://i; |
21
|
25
|
|
|
|
|
92
|
$value = Business::ISBN->new( $value ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
32
|
100
|
|
|
|
4598
|
return '' unless defined $value; |
25
|
|
|
|
|
|
|
|
26
|
27
|
|
|
|
|
104
|
my $status = $value->error; |
27
|
27
|
100
|
100
|
|
|
169
|
if ( $status != Business::ISBN::GOOD_ISBN && |
|
|
|
100
|
|
|
|
|
28
|
|
|
|
|
|
|
$status != Business::ISBN::INVALID_GROUP_CODE && |
29
|
|
|
|
|
|
|
$status != Business::ISBN::INVALID_PUBLISHER_CODE ) { |
30
|
2
|
|
|
|
|
24
|
return ''; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
25
|
100
|
|
|
|
126
|
$value = $value->as_isbn13 unless ref($value) eq 'Business::ISBN13'; |
34
|
|
|
|
|
|
|
|
35
|
25
|
|
|
|
|
2982
|
return $value->as_string([]); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub canonical { |
40
|
28
|
100
|
|
28
|
1
|
39
|
return ${$_[0]} eq '' ? '' : 'urn:isbn:' . ${$_[0]}; |
|
28
|
|
|
|
|
94
|
|
|
21
|
|
|
|
|
96
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub hash { |
45
|
15
|
|
|
15
|
1
|
5536
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# TODO: support use as constructor and as function |
48
|
|
|
|
|
|
|
|
49
|
15
|
100
|
|
|
|
38
|
if ( scalar @_ ) { |
50
|
9
|
|
|
|
|
11
|
my $value = shift; |
51
|
9
|
100
|
|
|
|
30
|
$value = defined $value ? "$value" : ""; |
52
|
9
|
100
|
100
|
|
|
56
|
$value = '' if not $value =~ /^[0-9]+$/ or $value >= 2000000000; |
53
|
9
|
100
|
|
|
|
19
|
if ( $value eq "" ) { |
54
|
5
|
|
|
|
|
7
|
$$self = ''; |
55
|
5
|
|
|
|
|
12
|
return ''; |
56
|
|
|
|
|
|
|
} |
57
|
4
|
|
|
|
|
30
|
my $isbn = Business::ISBN13->new( ($value+978000000000) . "X" ); |
58
|
4
|
|
|
|
|
626
|
$isbn->fix_checksum; |
59
|
4
|
|
|
|
|
370
|
$self->value( $isbn ); |
60
|
4
|
|
|
|
|
16
|
return $value; |
61
|
|
|
|
|
|
|
} else { |
62
|
6
|
100
|
|
|
|
72
|
return $$self eq '' ? '' : substr($$self, 2, 10 ) - 8000000000; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub isbn13 { |
68
|
1
|
|
|
1
|
1
|
372
|
my $self = shift; |
69
|
1
|
|
|
|
|
5
|
return $$self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub isbn10 { |
74
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
75
|
1
|
50
|
33
|
|
|
9
|
return '' if $$self eq '' or not $$self =~ /^978/; |
76
|
1
|
|
|
|
|
6
|
my $value = Business::ISBN->new( substr($$self,3) ); |
77
|
1
|
|
|
|
|
161
|
$value->fix_checksum; |
78
|
1
|
|
|
|
|
86
|
return $value->as_string([]); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |