line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
59557
|
use Carp qw(carp); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
2
|
|
|
|
|
|
|
carp "The xisbn service was due to be turned off on March 15, 2016."; |
3
|
|
|
|
|
|
|
package Business::xISBN; |
4
|
1
|
|
|
1
|
|
5
|
use Business::ISBN 2; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package # hide from PAUSE |
7
|
|
|
|
|
|
|
Business::ISBN; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
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.004"; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 Methods |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Loading this module adds these methods to the C class: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item xisbn |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
In scalar context, returns an anonymous array of related ISBNs using xISBN. |
51
|
|
|
|
|
|
|
In list context, returns a list. It does not include the original ISBN. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This feature uses L or L depending on |
54
|
|
|
|
|
|
|
which one it finds first. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
1
|
|
5
|
no warnings qw(redefine); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
371
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub xisbn { |
61
|
4
|
|
|
4
|
0
|
3417
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
19
|
my $data = $self->_get_xisbn; |
64
|
4
|
|
|
|
|
96
|
$data =~ tr/x/X/; |
65
|
|
|
|
|
|
|
|
66
|
4
|
|
|
|
|
13
|
my @isbns = do { |
67
|
4
|
50
|
|
|
|
376
|
if( eval "require Mojo::DOM; 1" ) { |
68
|
4
|
|
|
|
|
30
|
my $dom = Mojo::DOM->new( $data ); |
69
|
4
|
|
|
|
|
18121
|
$dom->find( 'isbn' )->map('text')->each; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
0
|
$data =~ m|(.*?)|g; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
4
|
|
|
|
|
14048
|
shift @isbns; |
77
|
4
|
100
|
|
|
|
36
|
wantarray ? @isbns : \@isbns; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _get_xisbn { |
81
|
4
|
|
|
4
|
|
11
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
4
|
|
|
|
|
9
|
my $data = eval { |
84
|
4
|
50
|
|
|
|
259
|
if( eval "require Mojo::UserAgent; 1" ) { |
|
|
0
|
|
|
|
|
|
85
|
4
|
|
|
|
|
41
|
Mojo::UserAgent->new->get( $self->_xisbn_url )->res->text; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif( eval "require LWP::Simple; 1" ) { |
88
|
0
|
|
|
|
|
0
|
LWP::Simple::get( $self->_xisbn_url ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
0
|
|
|
|
|
0
|
carp "Could not load either Mojo::UserAgent or LWP::Simple to fetch xISBN\n"; |
92
|
0
|
|
|
|
|
0
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
4
|
50
|
|
|
|
1038430
|
carp "Could not fetch xISBN data" unless defined $data; |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
18
|
return $data; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _xisbn_url { |
102
|
6
|
|
|
6
|
|
3165
|
my $self = shift; |
103
|
6
|
|
|
|
|
35
|
my $isbn = $self->as_string([]); |
104
|
|
|
|
|
|
|
|
105
|
6
|
|
|
|
|
300
|
return "http://xisbn.worldcat.org/xid/isbn/$isbn"; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |