--- trunk/Meteor/Koha.pm 2009/03/28 20:53:45 78 +++ trunk/Meteor/Koha.pm 2009/03/29 00:11:48 79 @@ -9,16 +9,27 @@ our $cache; +use HTML::Query qw/Query/; +use File::Slurp; +use Encode qw/decode/; +use Data::Dump qw/dump/; + sub item { my ( $class, $client, $item ) = @_; my $html; my $status = 200; + my $path = "cache/$item.html"; + if ( $html = $cache->{$item} ) { warn "# koha item $item from cache\n"; + } elsif ( 0 && -e $path ) { # FIXME enable + + $html = $cache->{$item} = read_file( $path ); + } else { my $url = 'http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=' . $item; @@ -28,11 +39,20 @@ if ($response->is_success) { $html = $response->content; - $html =~ s{.+?

}{

}s; - $html =~ s{
.+$}{}s; - $html =~ s{]+>}{}g; + + write_file( "cache/$item.koha.html", $html ); + + warn "## size before: ", length( $html ); + + $html = decode( 'utf-8', $html ); + my $q = Query( text => $html, 'div.container' ) + || die; + $html = $q->as_HTML->[0]; + + warn "## size after: ", length( $html ), dump( $html ); $cache->{$item} = $html; + write_file( $path, $html ); } else {