Add callback for receive-record.
[irspy-moved-to-github.git] / test-pod.pl
1 #!/usr/bin/perl -w
2
3 # $Id: test-pod.pl,v 1.2 2006-05-09 12:09:44 mike Exp $
4 #
5 # Run like this:
6 #       ZOOM_RECORD_NO_FORCE_SYNC=1 perl -I lib test-pod.pl
7 # (at least until the default sync. behaviour of ZOOM-C changes.)
8
9 use strict;
10 use warnings;
11
12 use ZOOM::Pod;
13
14 my $pod = new ZOOM::Pod("bagel.indexdata.com/gils",
15                         "z3950.loc.gov:7090/Voyager",
16                         "localhost:9999",
17                         );
18 $pod->callback(ZOOM::Event::RECV_SEARCH, \&completed_search);
19 $pod->callback(ZOOM::Event::RECV_RECORD, \&got_record);
20 $pod->search_pqf("mineral");
21 my $err = $pod->wait();
22 print "failed with error $err" if $err;
23
24 sub completed_search {
25     my($conn, $rs, $event) = @_;
26     print $conn->option("host"), ": found ", $rs->size(), " records\n";
27     my $rec = $rs->record(0);
28     print($conn->option("host"), ": rec(0) is ",
29           defined $rec ? ("$rec = '", $rec->render(), "'") : "undefined",
30           "\n");
31     return 0;
32 }
33
34 sub got_record {
35     my($conn, $rs, $event) = @_;
36     my $rec = $rs->record(0);
37     print $conn->option("host"), ": got 0: $rec = '", $rec->render(), "'\n";
38     return 0;
39 }