4 # YAZ_LOG=pod perl -I ../lib test-pod.pl "bagel.indexdata.com/gils" "bagel.indexdata.com/marc"
12 printf STDERR "Usage: $0 <target1> [<target2> ...]\n";
16 ZOOM::Log::mask_str("appl");
17 my $pod = new ZOOM::Pod(@ARGV);
18 $pod->option(elementSetName => "b");
19 $pod->callback(ZOOM::Event::RECV_SEARCH, \&completed_search);
20 $pod->callback(ZOOM::Event::RECV_RECORD, \&got_record);
21 #$pod->callback(exception => \&exception_thrown);
22 $pod->search_pqf("the");
23 my $err = $pod->wait({});
24 die "$pod->wait() failed with error $err" if $err;
26 sub completed_search {
27 my($conn, $arg, $rs, $event) = @_;
29 my $host = $conn->option("host");
30 print "$host : found ", $rs->size(), " records\n";
31 my %state = (next_to_show => 0, next_to_fetch => 0);
32 request_records($conn, $rs, \%state, 2);
33 $arg->{$host} = \%state;
38 my($conn, $arg, $rs, $event) = @_;
40 my $host = $conn->option("host");
41 my $state = $arg->{$host};
44 # Sanity-checking assertions. These should be impossible
45 my $ns = $state->{next_to_show};
46 my $nf = $state->{next_to_fetch};
48 die "next_to_show > next_to_fetch ($ns > $nf)";
49 } elsif ($ns == $nf) {
50 die "next_to_show == next_to_fetch ($ns)";
54 my $i = $state->{next_to_show}++;
55 my $rec = $rs->record($i);
56 print "$host: record $i is ", render_record($rec), "\n";
57 request_records($conn, $rs, $state, 3)
58 if $i == $state->{next_to_fetch}-1;
63 sub exception_thrown {
64 my($conn, $arg, $rs, $exception) = @_;
65 print "Uh-oh! $exception\n";
70 my($conn, $rs, $state, $count) = @_;
72 my $i = $state->{next_to_fetch};
73 ZOOM::Log::log("appl", "requesting $count records from $i for ",
74 $conn->option("host"));
75 $rs->records($i, $count, 0);
76 $state->{next_to_fetch} += $count;
82 return "undefined" if !defined $rec;
83 return "'" . $rec->render() . "'";