7 |
|
|
8 |
my $ua = LWP::UserAgent->new; |
my $ua = LWP::UserAgent->new; |
9 |
|
|
10 |
|
our $cache; |
11 |
|
|
12 |
sub item { |
sub item { |
13 |
my ( $class, $client, $item ) = @_; |
my ( $class, $client, $item ) = @_; |
14 |
|
|
15 |
my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; |
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 |
my $response = $ua->get( $url ); |
$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 |
my $html = $response->content; |
$cache->{$item} = $html; |
33 |
$html =~ s{<head>.+?<h1>}{<h1>}s; |
} |
|
$html =~ s{<div class="content_set">.+$}{}s; |
|
34 |
|
|
35 |
my $len = length($html); |
my $len = length($html); |
36 |
|
|
37 |
warn "# koha item $item [$len]\n"; |
warn "# koha item $item [$len]\n"; |
38 |
|
|
39 |
$client->write( |
$client->write( |
40 |
'HTTP/1.1 ' . $response->status_line . "\r\n" . |
"HTTP/1.1 200 OK\r\n" . |
41 |
"Content-Type: text/html\r\n" . |
"Content-Type: text/html\r\n" . |
42 |
"Content-length: $len\r\n" . |
"Content-length: $len\r\n" . |
43 |
"Connection: close\r\n" . |
"Connection: close\r\n" . |