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