give render module to pull usemap from
[Biblio-Z3950.git] / server.pl
index 6d26b06..7cc545f 100755 (executable)
--- a/server.pl
+++ b/server.pl
@@ -1,9 +1,11 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
+
+use warnings;
+use strict;
 
 use Net::Z3950::SimpleServer;
 use Net::Z3950::OID;
 use COBISS;
-use strict;
 
 my $max_records = 3; # XXX configure this
 my $max_result_sets = 10;
@@ -34,6 +36,7 @@ diag "SearchHandle ",Dumper($this);
     my $query;
 
     eval { $query = $rpn->{query}->render(); };
+       warn "ERROR: $@" if $@;
     if ( $@ && ref($@) ) {    ## Did someone/something report any errors?
         $this->{ERR_CODE} = $@->{errcode};
         $this->{ERR_STR}  = $@->{errstr};
@@ -44,6 +47,7 @@ diag "search for $query";
 
     my $setname  = $this->{SETNAME};
     my $repl_set = $this->{REPL_SET};
+diag "SETNAME $setname REPL_SET $repl_set";
     my $result;
     unless ( $result = COBISS->search( $query ) ) {
         $this->{ERR_CODE} = 108;
@@ -103,7 +107,11 @@ diag Dumper( $this );
     }
     elsif ( $req_form eq &Net::Z3950::OID::unimarc ) { # FIXME convert to usmarc
         $this->{REP_FORM} = &Net::Z3950::OID::unimarc;
-        $this->{RECORD} = COBISS->fetch_marc;
+        $this->{RECORD} = COBISS->fetch_rec('unimarc');
+    }
+    elsif ( $req_form eq &Net::Z3950::OID::usmarc ) {  # FIXME convert to usmarc
+        $this->{REP_FORM} = &Net::Z3950::OID::usmarc;
+        $this->{RECORD} = COBISS->fetch_rec('usmarc');
     }
     else {    ## Unsupported record format
         $this->{ERR_CODE} = 239;
@@ -153,12 +161,17 @@ sub render {
 
 package Net::Z3950::RPN::Term;
 
+use Data::Dump qw(dump);
 use COBISS;
 
 sub render {
-    my $this       = shift;
+    my ($this,$from) = @_;
+
+print "render ", dump($this);
 
-print "render ", $this;
+my $usemap = eval '$' . $from . '::usemap';
+die $@ if $@;
+warn "# $from usermap ",dump($usemap);
 
     my $attributes = {};
     my $prefix     = "";
@@ -168,7 +181,7 @@ print "render ", $this;
         $attributes->{$type} = $value;
     }
     if ( defined( my $use = $attributes->{1} ) ) {
-        if ( defined( my $field = COBISS::usemap($use) ) ) {
+        if ( defined( my $field = $usemap->{$use} ) ) {
             $prefix = $field;
         }
         else {