3 ## $Id: ztest.pl,v 1.15 2006-04-19 13:17:52 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;
33 use Net::Z3950::SimpleServer;
41 foreach $key (keys %$href) {
42 printf("%10s => %s\n", $key, $href->{$key});
51 $args->{IMP_NAME} = "DemoServer";
52 $args->{IMP_ID} = "81";
53 $args->{IMP_VER} = "3.14159";
54 $args->{ERR_CODE} = 0;
55 $args->{HANDLE} = $session;
56 if (defined($args->{PASS}) && defined($args->{USER})) {
57 printf("Received USER/PASS=%s/%s\n", $args->{USER},$args->{PASS});
66 print "Sort handler called\n";
67 print Dumper( $args );
72 my $term = $args->{TERM};
92 { TERM => 'Number 10',
96 $args->{ENTRIES} = $entries;
97 $args->{STATUS} = Net::Z3950::SimpleServer::ScanPartial;
98 print "Welcome to scan....\n";
99 print "You scanned for term '$term'\n";
103 sub my_search_handler {
106 name => "Peter Dornan",
107 title => "Spokesman",
108 collaboration => "ATLAS"
110 name => "Jorn Dines Hansen",
111 title => "Professor",
112 collaboration => "HERA-B"
114 name => "Alain Blondel",
115 title => "Head of coll.",
116 collaboration => "ALEPH"
119 my $session = $args->{HANDLE};
120 my $set_id = $args->{SETNAME};
121 my @database_list = @{ $args->{DATABASES} };
122 my $query = $args->{QUERY};
125 print "------------------------------------------------------------\n";
126 print "Processing query : $query\n";
127 printf("Database set : %s\n", join(" ", @database_list));
128 print "Setname : $set_id\n";
129 print "------------------------------------------------------------\n";
131 $args->{HITS} = $hits;
132 $session->{$set_id} = $data;
133 $session->{__HITS} = $hits;
137 sub my_fetch_handler {
139 my $session = $args->{HANDLE};
140 my $set_id = $args->{SETNAME};
141 my $data = $session->{$set_id};
142 my $offset = $args->{OFFSET};
143 my $record = "<xml>";
145 my $hits = $session->{__HITS};
146 my $href = $data->[$offset - 1];
148 $args->{REP_FORM} = Net::Z3950::OID::xml;
149 foreach $field (keys %$href) {
150 $record .= "<" . $field . ">" . $href->{$field} . "</" . $field . ">";
154 $args->{RECORD} = $record;
155 if ($offset == $session->{__HITS}) {
160 Net::Z3950::SimpleServer::yazlog("hello");
162 my $handler = new Net::Z3950::SimpleServer(
163 INIT => "main::my_init_handler",
164 SEARCH => "main::my_search_handler",
165 SCAN => "main::my_scan_handler",
166 SORT => "main::my_sort_handler",
167 FETCH => "main::my_fetch_handler" );
169 $handler->launch_server("ztest.pl", @ARGV);