From aa8ea4df68422b183c8f3ca8bf773e4db3a3b39c Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 12 Oct 2005 11:53:00 +0000 Subject: [PATCH] New --- samples/README | 30 ++++++++++++++++++++++++ samples/net-z3950-zoom/zoomtst1.pl | 43 ++++++++++++++++++++++++++++++++++ samples/net-z3950/zoomtst1.pl | 45 ++++++++++++++++++++++++++++++++++++ samples/zoom/zoomtst1.pl | 28 ++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 samples/README create mode 100644 samples/net-z3950-zoom/zoomtst1.pl create mode 100644 samples/net-z3950/zoomtst1.pl create mode 100644 samples/zoom/zoomtst1.pl diff --git a/samples/README b/samples/README new file mode 100644 index 0000000..6eeadec --- /dev/null +++ b/samples/README @@ -0,0 +1,30 @@ +$Id: README,v 1.1 2005-10-12 11:53:49 mike Exp $ + +This area contains sample programs that exercise all three of the APIs +supported by this module. The programs for each API are contained in +separate subdirectories: + +net-z3950-zoom -- Test programs using the low-level Net::Z3950::ZOOM + API, which is an as-literal-as-possible translation of the + ZOOM-C API. You should almost certainly not bother reading + these programs: they are for the benefit of the module + maintainers. + +zoom -- Test programs using the object-oriented ZOOM interface, which + is a nice, Perlish interpretation of the ZOOM abstract API as + documented at http://zoom.z3950.org/api/ + +net-z3950 -- Test programs using the obsolescent Net::Z3950 interface, + which is provided by this distribution as a plug-compatible + replacement for the old Net::Z3950 module. There is no reason + to use this API unless you are maintaining an existing + application that uses Net::Z3950. + +In general, each sample program exists in a different version in all +three directories, under the same name in each. The programs are: + +zoomtst1.pl -- A direct translation of the "zoomtst.c" application + from the YAZ distribution, except that these versions go on to + fetch the records that they find, whereas the C version is + satisfied just to get the hit count. + diff --git a/samples/net-z3950-zoom/zoomtst1.pl b/samples/net-z3950-zoom/zoomtst1.pl new file mode 100644 index 0000000..08b472a --- /dev/null +++ b/samples/net-z3950-zoom/zoomtst1.pl @@ -0,0 +1,43 @@ +# $Id: zoomtst1.pl,v 1.1 2005-10-12 11:53:11 mike Exp $ +# +# See ../README for a description of this program. +# perl -I../../blib/lib -I../../blib/arch zoomtst1.pl + +use strict; +use warnings; +use Net::Z3950::ZOOM; + +if (@ARGV != 2) { + print STDERR "Usage: $0 target query\n"; + print STDERR " eg. $0 bagel.indexdata.dk/gils computer\n"; + exit 1; +} + +my($host, $query) = @ARGV; +my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy"); + +my $conn = Net::Z3950::ZOOM::connection_new($host, 0); +$errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); +die("Can't connect to host '$host': ", + "errcode='$errcode', errmsg='$errmsg', addinfo='$addinfo'") + if $errcode != 0; + +Net::Z3950::ZOOM::connection_option_set($conn, + preferredRecordSyntax => "usmarc"); + +my $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query); +$errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); +die("Can't search for '$query': ", + "errcode='$errcode', errmsg='$errmsg', addinfo='$addinfo'") + if $errcode != 0; + +my $n = Net::Z3950::ZOOM::resultset_size($rs); +for my $i (0..$n-1) { + my $rec = Net::Z3950::ZOOM::resultset_record($rs, $i); + print "=== Record ", $i+1, " of $n ===\n"; + my $dummy = 0; + print Net::Z3950::ZOOM::record_get($rec, "render", $dummy); +} + +Net::Z3950::ZOOM::resultset_destroy($rs); +Net::Z3950::ZOOM::connection_destroy($conn); diff --git a/samples/net-z3950/zoomtst1.pl b/samples/net-z3950/zoomtst1.pl new file mode 100644 index 0000000..0d9033c --- /dev/null +++ b/samples/net-z3950/zoomtst1.pl @@ -0,0 +1,45 @@ +# $Id: zoomtst1.pl,v 1.1 2005-10-12 11:53:00 mike Exp $ +# +# See ../README for a description of this program. +# perl -I../../blib/lib -I../../blib/arch zoomtst1.pl + +use strict; +use warnings; +use Net::Z3950; + +if (@ARGV != 2) { + print STDERR "Usage: $0 target query\n"; + print STDERR " eg. $0 bagel.indexdata.dk/gils computer\n"; + exit 1; +} + +my($host, $query) = @ARGV; + +### Database name defaults to "Default" in Net::Z3950 and must be overridden +$host =~ s/\/(.*)//; +my $db = $1; +my $conn = new Net::Z3950::Connection($host, 0, databaseName => $db) + or die "can't connect to '$host': $!"; + +### Default format is GRS-1 in Net::Z3950 +$conn->option(preferredRecordSyntax => "usmarc"); + +### Default format is "B" in Net::Z3950 +$conn->option(elementSetName => "F"); + +my $rs = $conn->search(-prefix => $query) + or die "can't search for '$query': ", $conn->errmsg(); +my $n = $rs->size(); + +### Note that the record-index is 1-based here, 0-based in ZOOM-C +for my $i (1..$n) { + my $rec = $rs->record($i) + or die "can't fetch record $i: ", $rs->errmsg(); + print "=== Record $i of $n ===\n"; + + ### Rendering format for MARC records is different + print $rec->render(), "\n"; +} + +$rs->delete(); +$conn->close(); diff --git a/samples/zoom/zoomtst1.pl b/samples/zoom/zoomtst1.pl new file mode 100644 index 0000000..5e05f54 --- /dev/null +++ b/samples/zoom/zoomtst1.pl @@ -0,0 +1,28 @@ +# $Id: zoomtst1.pl,v 1.1 2005-10-12 11:53:27 mike Exp $ +# +# See ../README for a description of this program. +# perl -I../../blib/lib -I../../blib/arch zoomtst1.pl + +use strict; +use warnings; +use ZOOM; + +if (@ARGV != 2) { + print STDERR "Usage: $0 target query\n"; + print STDERR " eg. $0 bagel.indexdata.dk/gils computer\n"; + exit 1; +} + +my($host, $query) = @ARGV; +my $conn = new ZOOM::Connection($host, 0); +$conn->option(preferredRecordSyntax => "usmarc"); +my $rs = $conn->search_pqf($query); +my $n = $rs->size(); +for my $i (0..$n-1) { + my $rec = $rs->record($i); + print "=== Record ", $i+1, " of $n ===\n"; + print $rec->render(); +} + +$rs->destroy(); +$conn->destroy(); -- 1.7.10.4