line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Plugin::LibraryThing; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
41171
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
36
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
670
|
use Dancer::Plugin; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use WWW::LibraryThing::Covers; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Dancer::Plugin::LibraryThing - Plugin for LibraryThing APIs. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.0003 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.0003'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my %lt_object; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Dancer::Plugin::LibraryThing; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
get '/images/covers/*.jpg' => sub { |
29
|
|
|
|
|
|
|
my ($isbn) = splat; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
unless (-f "public/images/covers/$isbn.jpg") { |
32
|
|
|
|
|
|
|
@ret = librarything_cover($isbn); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if (@ret < 3) { |
35
|
|
|
|
|
|
|
debug("Error retrieving cover for ISBN $isbn"); |
36
|
|
|
|
|
|
|
status 'not_found'; |
37
|
|
|
|
|
|
|
forward 404; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return send_file "images/covers/$isbn.jpg"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Retrieves book covers from LibraryThing based on ISBN-10 numbers. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Please checkout the terms of use first. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 CONFIGURATION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
plugins: |
53
|
|
|
|
|
|
|
LibraryThing: |
54
|
|
|
|
|
|
|
api_key: d231aa37c9b4f5d304a60a3d0ad1dad4 |
55
|
|
|
|
|
|
|
directory: public/images/covers |
56
|
|
|
|
|
|
|
size: large |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Size defaults to medium. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 FUNCTIONS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 librarything_cover |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Requests a cover from LibraryThing and stores it in the |
65
|
|
|
|
|
|
|
directory set in the configuration. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
First (mandatory) parameter is the ISBN-10 number. Optional |
68
|
|
|
|
|
|
|
parameters can be given as hash (directory and size), defaults |
69
|
|
|
|
|
|
|
are given in the configuration. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
register librarything_cover => sub { |
74
|
|
|
|
|
|
|
my ($isbn, %arg) = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $directory = $arg{directory} || plugin_setting->{directory}; |
77
|
|
|
|
|
|
|
my $size = $arg{size} || plugin_setting->{size}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $key = $size . "\t" . $directory; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
unless ($lt_object{$key}) { |
82
|
|
|
|
|
|
|
$lt_object{$key} = WWW::LibraryThing::Covers->new( |
83
|
|
|
|
|
|
|
api_key => plugin_setting->{api_key}, |
84
|
|
|
|
|
|
|
directory => $directory, |
85
|
|
|
|
|
|
|
size => $size |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$lt_object{$key}->get($isbn); |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
register_plugin; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Stefan Hornburg (Racke), C<< >> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 BUGS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
101
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
102
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SUPPORT |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
perldoc Dancer::Plugin::LibraryThing |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
You can also look for information at: |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * CPAN Ratings |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * Search CPAN |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=back |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
None so far. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Copyright 2011 Stefan Hornburg (Racke). |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
146
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
147
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; # End of Dancer::Plugin::LibraryThing |