/[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

Annotation of /trunk/Meteor/Koha.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71 - (hide annotations)
Sat Mar 28 14:20:59 2009 UTC (15 years, 1 month ago) by dpavlin
File size: 795 byte(s)
item in-memory cache
1 dpavlin 70 package Meteor::Koha;
2    
3     use strict;
4     use warnings;
5    
6     use LWP::UserAgent;
7    
8     my $ua = LWP::UserAgent->new;
9    
10 dpavlin 71 our $cache;
11    
12 dpavlin 70 sub item {
13     my ( $class, $client, $item ) = @_;
14    
15 dpavlin 71 my $html;
16 dpavlin 70
17 dpavlin 71 if ( $html = $cache->{$item} ) {
18 dpavlin 70
19 dpavlin 71 warn "# koha item $item from cache\n";
20 dpavlin 70
21 dpavlin 71 } 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 dpavlin 70 my $len = length($html);
36    
37     warn "# koha item $item [$len]\n";
38    
39     $client->write(
40 dpavlin 71 "HTTP/1.1 200 OK\r\n" .
41 dpavlin 70 "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;

  ViewVC Help
Powered by ViewVC 1.1.26