From d658a9bf604ae2512ca0983b547eea8369ef34a7 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 5 May 2006 22:14:46 +0000 Subject: [PATCH] New --- lib/ZOOM/Pod.pm | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test-pod.pl | 21 ++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 lib/ZOOM/Pod.pm create mode 100644 test-pod.pl diff --git a/lib/ZOOM/Pod.pm b/lib/ZOOM/Pod.pm new file mode 100644 index 0000000..b700857 --- /dev/null +++ b/lib/ZOOM/Pod.pm @@ -0,0 +1,83 @@ +# $Id: Pod.pm,v 1.1 2006-05-05 22:17:02 mike Exp $ + +package ZOOM::Pod; + +use strict; +use warnings; + +use ZOOM; + +=head1 SYNOPSIS + + $conn1 = new ZOOM::Connection("bagel.indexdata.com/gils"); + $conn2 = new ZOOM::Connection("z3950.loc.gov:7090/Voyager"); + $pod = new ZOOM::Pod($conn1, $conn2); + $pod->callback(ZOOM::Event::RECV_SEARCH, \&show_result); + $pod->search_pqf("mineral"); + $pod->wait(); + + sub show_result { + ($conn, $rs, $event) = @_; + print "$conn: found ", $rs->size(), " records\n"; + } + +=cut + +sub new { + my $class = shift(); + my(@conn) = @_; + + foreach my $conn (@conn) { + if (!ref $conn) { + $conn = new ZOOM::Connection($conn, 0, async => 1); + } + } + + return bless { + conn => \@conn, + rs => [], + callback => {}, + }, $class; +} + +sub callback { + my $this = shift(); + my($event, $sub) = @_; + + my $old = $this->{callback}->{$event}; + $this->{callback}->{$event} = $sub + if defined $sub; + + return $old; +} + +sub search_pqf { + my $this = shift(); + my($pqf) = @_; + + foreach my $i (0..@{ $this->{conn} }-1) { + $this->{rs}->[$i] = $this->{conn}->[$i]->search_pqf($pqf); + } +} + +sub wait { + my $this = shift(); + my $res = 0; + + print "in wait\n"; + while ((my $i = ZOOM::event($this->{conn})) != 0) { + my $conn = $this->{conn}->[$i-1]; + my $ev = $conn->last_event(); + print("connection ", $i-1, ": ", ZOOM::event_str($ev), "\n"); + my $sub = $this->{callback}->{$ev}; + if (defined $sub) { + $res = &$sub($conn, $this->{rs}->[$i-1], $ev); + last if $res != 0; + } + } + + return $res; +} + + +1; diff --git a/test-pod.pl b/test-pod.pl new file mode 100644 index 0000000..12d8715 --- /dev/null +++ b/test-pod.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w + +# $Id: test-pod.pl,v 1.1 2006-05-05 22:14:46 mike Exp $ + +use strict; +use warnings; + +use ZOOM::Pod; + +my $pod = new ZOOM::Pod("bagel.indexdata.com/gils", + "z3950.loc.gov:7090/Voyager"); +$pod->callback(ZOOM::Event::RECV_SEARCH, \&show_result); +$pod->search_pqf("mineral"); +my $err = $pod->wait(); +print "failed with error $err" if $err; + +sub show_result { + my($conn, $rs, $event) = @_; + print $conn->option("host"), ": found ", $rs->size(), " records\n"; + return 0; +} -- 1.7.10.4