/[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 77 - (hide annotations)
Sat Mar 28 20:53:20 2009 UTC (11 years, 3 months ago) by dpavlin
File size: 951 byte(s)
return 404 on error
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 77 my $status = 200;
17 dpavlin 70
18 dpavlin 71 if ( $html = $cache->{$item} ) {
19 dpavlin 70
20 dpavlin 71 warn "# koha item $item from cache\n";
21 dpavlin 70
22 dpavlin 71 } 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 dpavlin 77 if ($response->is_success) {
29 dpavlin 71
30 dpavlin 77 $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 dpavlin 71 }
44    
45 dpavlin 70 my $len = length($html);
46    
47     warn "# koha item $item [$len]\n";
48    
49     $client->write(
50 dpavlin 77 "HTTP/1.1 $status OK\r\n" .
51 dpavlin 70 "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