3 ## $Id: ztest.pl,v 1.13 2004-05-28 20:27:16 sondberg Exp $
4 ## ------------------------------------------------------------------
6 ## Copyright (c) 2000-2004, Index Data.
8 ## Permission to use, copy, modify, distribute, and sell this software and
9 ## its documentation, in whole or in part, for any purpose, is hereby granted,
12 ## 1. This copyright and permission notice appear in all copies of the
13 ## software and its documentation. Notices of copyright or attribution
14 ## which appear at the beginning of any file must remain unchanged.
16 ## 2. The name of Index Data or the individual authors may not be used to
17 ## endorse or promote products derived from this software without specific
18 ## prior written permission.
20 ## THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
21 ## EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
22 ## WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
23 ## IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
24 ## INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
25 ## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
26 ## NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
27 ## LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
31 use ExtUtils::testlib;
32 use Net::Z3950::SimpleServer;
40 foreach $key (keys %$href) {
41 printf("%10s => %s\n", $key, $href->{$key});
50 $args->{IMP_NAME} = "DemoServer";
51 $args->{IMP_ID} = "81";
52 $args->{IMP_VER} = "3.14159";
53 $args->{ERR_CODE} = 0;
54 $args->{HANDLE} = $session;
55 if (defined($args->{PASS}) && defined($args->{USER})) {
56 printf("Received USER/PASS=%s/%s\n", $args->{USER},$args->{PASS});
63 my $term = $args->{TERM};
83 { TERM => 'Number 10',
87 $args->{ENTRIES} = $entries;
88 $args->{STATUS} = Net::Z3950::SimpleServer::ScanPartial;
89 print "Welcome to scan....\n";
90 print "You scanned for term '$term'\n";
94 sub my_search_handler {
97 name => "Peter Dornan",
99 collaboration => "ATLAS"
101 name => "Jorn Dines Hansen",
102 title => "Professor",
103 collaboration => "HERA-B"
105 name => "Alain Blondel",
106 title => "Head of coll.",
107 collaboration => "ALEPH"
110 my $session = $args->{HANDLE};
111 my $set_id = $args->{SETNAME};
112 my @database_list = @{ $args->{DATABASES} };
113 my $query = $args->{QUERY};
116 print "------------------------------------------------------------\n";
117 print "Processing query : $query\n";
118 printf("Database set : %s\n", join(" ", @database_list));
119 print "Setname : $set_id\n";
120 print "------------------------------------------------------------\n";
122 $args->{HITS} = $hits;
123 $session->{$set_id} = $data;
124 $session->{__HITS} = $hits;
128 sub my_fetch_handler {
130 my $session = $args->{HANDLE};
131 my $set_id = $args->{SETNAME};
132 my $data = $session->{$set_id};
133 my $offset = $args->{OFFSET};
134 my $record = "<xml>";
136 my $hits = $session->{__HITS};
137 my $href = $data->[$offset - 1];
139 $args->{REP_FORM} = Net::Z3950::OID::xml;
140 foreach $field (keys %$href) {
141 $record .= "<" . $field . ">" . $href->{$field} . "</" . $field . ">";
145 $args->{RECORD} = $record;
146 if ($offset == $session->{__HITS}) {
152 my $handler = new Net::Z3950::SimpleServer(
153 INIT => "main::my_init_handler",
154 SEARCH => "main::my_search_handler",
155 SCAN => "main::my_scan_handler",
156 FETCH => "main::my_fetch_handler" );
158 $handler->launch_server("ztest.pl", @ARGV);