1 |
package Meteor::Koha; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use LWP::UserAgent; |
7 |
|
8 |
my $ua = LWP::UserAgent->new; |
9 |
|
10 |
our $cache; |
11 |
|
12 |
sub item { |
13 |
my ( $class, $client, $item ) = @_; |
14 |
|
15 |
my $html; |
16 |
|
17 |
if ( $html = $cache->{$item} ) { |
18 |
|
19 |
warn "# koha item $item from cache\n"; |
20 |
|
21 |
} else { |
22 |
|
23 |
my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; |
24 |
|
25 |
my $response = $ua->get( $url ); |
26 |
|
27 |
$html = $response->content; |
28 |
$html =~ s{<head>.+?<h1>}{<h1>}s; |
29 |
$html =~ s{<div class="content_set">.+$}{}s; |
30 |
$html =~ s{</?img[^>]+>}{}g; |
31 |
|
32 |
$cache->{$item} = $html; |
33 |
} |
34 |
|
35 |
my $len = length($html); |
36 |
|
37 |
warn "# koha item $item [$len]\n"; |
38 |
|
39 |
$client->write( |
40 |
"HTTP/1.1 200 OK\r\n" . |
41 |
"Content-Type: text/html\r\n" . |
42 |
"Content-length: $len\r\n" . |
43 |
"Connection: close\r\n" . |
44 |
"\r\n\r\n$html\r\n" |
45 |
); |
46 |
|
47 |
} |
48 |
|
49 |
1; |