/[meteor]/trunk/Meteor/Koha.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/Meteor/Koha.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (show annotations)
Sat Mar 28 20:53:20 2009 UTC (15 years ago) by dpavlin
File size: 951 byte(s)
return 404 on error
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 my $status = 200;
17
18 if ( $html = $cache->{$item} ) {
19
20 warn "# koha item $item from cache\n";
21
22 } else {
23
24 my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item;
25
26 my $response = $ua->get( $url );
27
28 if ($response->is_success) {
29
30 $html = $response->content;
31 $html =~ s{<head>.+?<h1>}{<h1>}s;
32 $html =~ s{<div class="content_set">.+$}{}s;
33 $html =~ s{</?img[^>]+>}{}g;
34
35 $cache->{$item} = $html;
36
37 } else {
38
39 $html = qq{Can't load $item } . $response->status_line;
40 # $status = 404;
41
42 }
43 }
44
45 my $len = length($html);
46
47 warn "# koha item $item [$len]\n";
48
49 $client->write(
50 "HTTP/1.1 $status OK\r\n" .
51 "Content-Type: text/html\r\n" .
52 "Content-length: $len\r\n" .
53 "Connection: close\r\n" .
54 "\r\n\r\n$html\r\n"
55 );
56
57 }
58
59 1;

  ViewVC Help
Powered by ViewVC 1.1.26