| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
49354
|
use Carp qw(carp); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
65
|
|
|
2
|
|
|
|
|
|
|
carp "The xisbn service was due to be turned off on March 15, 2016."; |
|
3
|
|
|
|
|
|
|
package Business::xISBN; |
|
4
|
1
|
|
|
1
|
|
6
|
use Business::ISBN 2; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package # hide from PAUSE |
|
7
|
|
|
|
|
|
|
Business::ISBN; |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
49
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=encoding utf8 |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Business::xISBN - access the xISBN service |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Business::ISBN; |
|
20
|
|
|
|
|
|
|
use Business::xISBN; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# maybe you don't care what it is as long as everything works |
|
23
|
|
|
|
|
|
|
my $isbn = Business::ISBN->new( $ARGV[0] ); |
|
24
|
|
|
|
|
|
|
my @xisbns = $isbn->xisbn; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This is a mixin for L. Although it looks like it has |
|
30
|
|
|
|
|
|
|
a different package name, it really declares methods to L. |
|
31
|
|
|
|
|
|
|
This means that you can use this module and not change code from the 2.x |
|
32
|
|
|
|
|
|
|
major version of L. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This is not a complete interface to xISBN. It merely retrieves related |
|
35
|
|
|
|
|
|
|
ISBNs. If someone wants to expand this to handle other parts of the API, |
|
36
|
|
|
|
|
|
|
send a pull request! |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$VERSION = "1.003"; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item xisbn |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
In scalar context, returns an anonymous array of related ISBNs using xISBN. |
|
45
|
|
|
|
|
|
|
In list context, returns a list. It does not include the original ISBN. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This feature uses L or L depending on |
|
48
|
|
|
|
|
|
|
which one it finds first. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
1
|
|
|
1
|
|
6
|
no warnings qw(redefine); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
401
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub xisbn { |
|
55
|
4
|
|
|
4
|
0
|
3251
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
15
|
my $data = $self->_get_xisbn; |
|
58
|
4
|
|
|
|
|
175
|
$data =~ tr/x/X/; |
|
59
|
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
16
|
my @isbns = do { |
|
61
|
4
|
50
|
|
|
|
600
|
if( eval "require Mojo::DOM; 1" ) { |
|
62
|
4
|
|
|
|
|
34
|
my $dom = Mojo::DOM->new( $data ); |
|
63
|
4
|
|
|
|
|
26024
|
$dom->find( 'isbn' )->map('text')->each; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
else { |
|
66
|
0
|
|
|
|
|
0
|
$data =~ m|(.*?)|g; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
}; |
|
69
|
|
|
|
|
|
|
|
|
70
|
4
|
|
|
|
|
12899
|
shift @isbns; |
|
71
|
4
|
100
|
|
|
|
52
|
wantarray ? @isbns : \@isbns; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _get_xisbn { |
|
75
|
4
|
|
|
4
|
|
8
|
my $self = shift; |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
7
|
my $data = eval { |
|
78
|
4
|
50
|
|
|
|
299
|
if( eval "require Mojo::UserAgent; 1" ) { |
|
|
|
0
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
34
|
Mojo::UserAgent->new->get( $self->_xisbn_url )->res->text; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
elsif( eval "require LWP::Simple; 1" ) { |
|
82
|
0
|
|
|
|
|
0
|
LWP::Simple::get( $self->_xisbn_url ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
else { |
|
85
|
0
|
|
|
|
|
0
|
carp "Could not load either Mojo::UserAgent or LWP::Simple to fetch xISBN\n"; |
|
86
|
0
|
|
|
|
|
0
|
return; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
}; |
|
89
|
|
|
|
|
|
|
|
|
90
|
4
|
50
|
|
|
|
1239609
|
carp "Could not fetch xISBN data" unless defined $data; |
|
91
|
|
|
|
|
|
|
|
|
92
|
4
|
|
|
|
|
33
|
return $data; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _xisbn_url { |
|
96
|
6
|
|
|
6
|
|
3093
|
my $self = shift; |
|
97
|
6
|
|
|
|
|
24
|
my $isbn = $self->as_string([]); |
|
98
|
|
|
|
|
|
|
|
|
99
|
6
|
|
|
|
|
151
|
return "http://xisbn.worldcat.org/xid/isbn/$isbn"; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |