1 # $Id: Pod.pm,v 1.5 2006-05-10 16:01:04 mike Exp $
11 # Just register the name
12 ZOOM::Log::mask_str("pod");
13 ZOOM::Log::mask_str("pod_unhandled");
18 ZOOM::Pod - Perl extension for handling pods of concurrent ZOOM connections
24 $pod = new ZOOM::Pod("bagel.indexdata.com/gils",
25 "bagel.indexdata.com/marc");
26 $pod->callback(ZOOM::Event::RECV_SEARCH, \&completed_search);
27 $pod->callback(ZOOM::Event::RECV_RECORD, \&got_record);
28 $pod->search_pqf("the");
30 die "$pod->wait() failed with error $err" if $err;
32 sub completed_search {
33 ($conn, undef, $rs) = @_;
34 print $conn->option("host"), ": found ", $rs->size(), " records\n";
35 $rs->records(0, 1, 0); # Queues a request for the record
40 ($conn, undef, $rs) = @_;
41 $rec = $rs->record(0);
42 print $conn->option("host"), ": got $rec = '", $rec->render(), "'\n";
58 die "$class with no connections" if @conn == 0;
59 my @state; # Hashrefs with application state associated with connections
60 foreach my $conn (@conn) {
62 $conn = new ZOOM::Connection($conn, 0, async => 1);
63 # The $conn object is always made, even if no there's no
64 # server. Such errors are caught later, by the _check()
80 my($key, $value) = @_;
82 foreach my $conn (@{ $this->{conn} }) {
83 $conn->option($key, $value);
89 my($event, $sub) = @_;
91 my $old = $this->{callback}->{$event};
92 $this->{callback}->{$event} = $sub
102 foreach my $i (0..@{ $this->{conn} }-1) {
103 $this->{rs}->[$i] = $this->{conn}->[$i]->search_pqf($pqf);
111 while ((my $i = ZOOM::event($this->{conn})) != 0) {
112 my $conn = $this->{conn}->[$i-1];
113 my $ev = $conn->last_event();
114 my $evstr = ZOOM::event_str($ev);
115 ZOOM::Log::log("pod", "connection ", $i-1, ": $evstr");
120 my $sub = $this->{callback}->{exception};
121 die $@ if !defined $sub;
122 $res = &$sub($conn, $this->{state}->[$i-1],
123 $this->{rs}->[$i-1], $@);
128 my $sub = $this->{callback}->{$ev};
130 $res = &$sub($conn, $this->{state}->[$i-1],
131 $this->{rs}->[$i-1], $ev);
134 ZOOM::Log::log("pod_unhandled", "unhandled event $ev ($evstr)");
152 Mike Taylor, E<lt>mike@indexdata.comE<gt>
154 =head1 COPYRIGHT AND LICENCE
156 Copyright (C) 2006 by Index Data.
158 This library is free software; you can redistribute it and/or modify
159 it under the same terms as Perl itself, either Perl version 5.8.4 or,
160 at your option, any later version of Perl 5 you may have available.