37c54efe6f845f73dc9d78e1c875ea70c8612a5f
[irspy-moved-to-github.git] / test-pod.pl
1 #!/usr/bin/perl -w
2
3 # $Id: test-pod.pl,v 1.5 2006-05-10 13:33:13 mike Exp $
4 #
5 # Run like this:
6 #       YAZ_LOG=pod perl -I lib test-pod.pl "bagel.indexdata.com/gils" "bagel.indexdata.com/marc"
7
8 use strict;
9 use warnings;
10
11 use ZOOM::Pod;
12
13 my $pod = new ZOOM::Pod(@ARGV);
14 $pod->option(elementSetName => "b");
15 $pod->callback(ZOOM::Event::RECV_SEARCH, \&completed_search);
16 $pod->callback(ZOOM::Event::RECV_RECORD, \&got_record);
17 $pod->search_pqf("the");
18 my $err = $pod->wait();
19 die "$pod->wait() failed with error $err" if $err;
20
21 sub completed_search {
22     my($conn, $state, $rs, $event) = @_;
23     print $conn->option("host"), ": found ", $rs->size(), " records\n";
24     $state->{next_to_fetch} = 0;
25     $state->{next_to_show} = 0;
26     request_records($conn, $rs, $state, 2);
27     return 0;
28 }
29
30 sub got_record {
31     my($conn, $state, $rs, $event) = @_;
32
33     {
34         # Sanity-checking assertions.  These should be impossible
35         my $ns = $state->{next_to_show};
36         my $nf = $state->{next_to_fetch};
37         if ($ns > $nf) {
38             die "next_to_show > next_to_fetch ($ns > $nf)";
39         } elsif ($ns == $nf) {
40             die "next_to_show == next_to_fetch ($ns)";
41         }
42     }
43
44     my $i = $state->{next_to_show}++;
45     my $rec = $rs->record($i);
46     print $conn->option("host"), ": record $i is ", render_record($rec), "\n";
47     request_records($conn, $rs, $state, 3)
48         if $i == $state->{next_to_fetch}-1;
49
50     return 0;
51 }
52
53 sub request_records {
54     my($conn, $rs, $state, $count) = @_;
55
56     my $i = $state->{next_to_fetch};
57     ZOOM::Log::log("appl", "requesting $count records from $i");
58     $rs->records($i, $count, 0);
59     $state->{next_to_fetch} += $count;
60 }
61
62 sub render_record {
63     my($rec) = @_;
64
65     return "undefined" if !defined $rec;
66     return "'" . $rec->render() . "'";
67 }