From 692fb30bc0ab6d6e1536405ed7040ecd2b7c94ce Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 15 Jun 2006 15:43:13 +0000 Subject: [PATCH] Many changes to accomodate modified ZOOM_query_ccl2rpn() API --- Changes | 7 ++++++- ZOOM.xs | 16 ++++++++++++---- lib/ZOOM.pm | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- t/12-query.t | 24 ++++++++++++++---------- t/15-scan.t | 8 ++++---- t/22-query.t | 6 +++--- 6 files changed, 87 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index 9c0f53d..55139de 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,12 @@ -$Id: Changes,v 1.36 2006-06-13 16:44:51 mike Exp $ +$Id: Changes,v 1.37 2006-06-15 15:43:13 mike Exp $ Revision history for Perl extension Net::Z3950::ZOOM. +1.10 Thu Jun 15 16:42:47 BST 2006 + - No functional changes, but use Adam's modified API to + ZOOM_query_ccl2rpn(). This incompatible change means that + RELEASE 1.09 WILL NOT BUILD against any recent YAZ. + 1.09 Tue Jun 13 17:44:43 2006 - Add new function Net::Z3950::ZOOM::query_ccl2rpn(), for client-side CCL compilation. diff --git a/ZOOM.xs b/ZOOM.xs index ce41632..7f02c01 100644 --- a/ZOOM.xs +++ b/ZOOM.xs @@ -1,4 +1,4 @@ -/* $Id: ZOOM.xs,v 1.41 2006-06-13 16:44:21 mike Exp $ */ +/* $Id: ZOOM.xs,v 1.42 2006-06-15 15:43:13 mike Exp $ */ #include "EXTERN.h" #include "perl.h" @@ -327,10 +327,18 @@ ZOOM_query_cql2rpn(s, str, conn) ZOOM_connection conn int -ZOOM_query_ccl2rpn(s, str, conn) +ZOOM_query_ccl2rpn(s, query_str, config, errcode, errstr, errpos) ZOOM_query s - const char* str - ZOOM_connection conn + const char* query_str + const char* config + int &errcode + const char* &errstr + int &errpos + OUTPUT: + RETVAL + errcode + errstr + errpos int ZOOM_query_prefix(s, str) diff --git a/lib/ZOOM.pm b/lib/ZOOM.pm index f553382..28dc285 100644 --- a/lib/ZOOM.pm +++ b/lib/ZOOM.pm @@ -1,7 +1,8 @@ -# $Id: ZOOM.pm,v 1.34 2006-06-13 16:44:21 mike Exp $ +# $Id: ZOOM.pm,v 1.35 2006-06-15 15:43:14 mike Exp $ use strict; use warnings; +use IO::File; use Net::Z3950::ZOOM; @@ -53,6 +54,22 @@ sub PACKAGE { 20006 } sub SCANTERM { 20007 } sub LOGLEVEL { 20008 } +# Separate space for CCL errors. Great. +package ZOOM::CCL::Error; +sub OK { Net::Z3950::ZOOM::CCL_ERR_OK } +sub TERM_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED } +sub RP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_RP_EXPECTED } +sub SETNAME_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_SETNAME_EXPECTED } +sub OP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_OP_EXPECTED } +sub BAD_RP { Net::Z3950::ZOOM::CCL_ERR_BAD_RP } +sub UNKNOWN_QUAL { Net::Z3950::ZOOM::CCL_ERR_UNKNOWN_QUAL } +sub DOUBLE_QUAL { Net::Z3950::ZOOM::CCL_ERR_DOUBLE_QUAL } +sub EQ_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_EQ_EXPECTED } +sub BAD_RELATION { Net::Z3950::ZOOM::CCL_ERR_BAD_RELATION } +sub TRUNC_NOT_LEFT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_LEFT } +sub TRUNC_NOT_BOTH { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_BOTH } +sub TRUNC_NOT_RIGHT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_RIGHT } + # The "Event" package contains constants returned by last_event() package ZOOM::Event; sub NONE { Net::Z3950::ZOOM::EVENT_NONE } @@ -110,7 +127,7 @@ sub event { sub _oops { my($code, $addinfo, $diagset) = @_; - die new ZOOM::Exception($code, diag_str($code), $addinfo, $diagset); + die new ZOOM::Exception($code, undef, $addinfo, $diagset); } # ---------------------------------------------------------------------------- @@ -121,11 +138,18 @@ sub new { my $class = shift(); my($code, $message, $addinfo, $diagset) = @_; + $diagset ||= "ZOOM"; + if ($diagset eq "ZOOM") { + $message ||= ZOOM::diag_str($code); + } else { + # Should fill in messages for other diagsets, too. + } + return bless { code => $code, message => $message, addinfo => $addinfo, - diagset => $diagset || "ZOOM", + diagset => $diagset, }, $class; } @@ -546,7 +570,7 @@ sub new { } -# It's distressing how very similar this is to CQL2RPN +# We have to work around the retarded ZOOM_query_ccl2rpn() API package ZOOM::Query::CCL2RPN; our @ISA = qw(ZOOM::Query); @@ -556,9 +580,26 @@ sub new { my $q = Net::Z3950::ZOOM::query_create() or ZOOM::_oops(ZOOM::Error::CREATE_QUERY); - # check() throws the exception we want; but we only want it on failure! - Net::Z3950::ZOOM::query_ccl2rpn($q, $string, $conn->_conn()) == 0 - or $conn->_check(); + + my $config = $conn->option("cclqual"); + if (!defined $config) { + my $cclfile = $conn->option("cclfile") + or ZOOM::_oops(ZOOM::Error::CCL_CONFIG, + "no 'cclqual' or 'cclfile' specified"); + my $fh = new IO::File("<$cclfile") + or ZOOM::_oops(ZOOM::Error::CCL_CONFIG, + "can't open cclfile '$cclfile': $!"); + $config = join("", <$fh>); + $fh->close(); + } + + my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0); + if (Net::Z3950::ZOOM::query_ccl2rpn($q, $string, $config, + $ccl_errcode, $ccl_errstr, + $ccl_errpos) < 0) { + # We have no use for $ccl_errcode or $ccl_errpos + ZOOM::_oops(ZOOM::Error::CCL_PARSE, $ccl_errstr); + } return bless { _query => $q, diff --git a/t/12-query.t b/t/12-query.t index eb4fa3d..39ff941 100644 --- a/t/12-query.t +++ b/t/12-query.t @@ -1,4 +1,4 @@ -# $Id: 12-query.t,v 1.6 2006-06-13 16:15:12 mike Exp $ +# $Id: 12-query.t,v 1.7 2006-06-15 15:43:19 mike Exp $ # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 12-query.t' @@ -102,18 +102,19 @@ ok($res == 0, "created CQL2RPN query"); check_record($conn, $q); Net::Z3950::ZOOM::query_destroy($q); -# Client-side compiled CCL: this will fail due to lack of qualifier-file +# Client-side compiled CCL: this will fail due to incorrect syntax $q = Net::Z3950::ZOOM::query_create(); ok(defined $q, "create empty query"); +my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0); + +### change documentation $res = Net::Z3950::ZOOM::query_ccl2rpn($q, - 'ti=utah and ab=epicenter', - $conn); -$errcode = Net::Z3950::ZOOM::connection_error_x($conn, $errmsg, $addinfo, - $diagset); + 'ti=utah and', + "ti u=4 s=pw\nab u=62 s=pw", + $ccl_errcode, $ccl_errstr, $ccl_errpos); ok($res < 0 && - $errcode == Net::Z3950::ZOOM::ERROR_CCL_CONFIG && - $diagset eq "ZOOM", - "can't make CCL2RPN query: error " . $errcode); + $ccl_errcode == Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED, + "can't make CCL2RPN query: error $ccl_errcode ($ccl_errstr)"); Net::Z3950::ZOOM::query_destroy($q); # Do a successful client-compiled CCL search @@ -123,7 +124,10 @@ Net::Z3950::ZOOM::connection_option_set($conn, cclfile => "samples/ccl/default.bib"); $res = Net::Z3950::ZOOM::query_ccl2rpn($q, 'ti=utah and ab=epicenter', - $conn); + "ti u=4 s=pw\nab u=62 s=pw", + $ccl_errcode, + $ccl_errstr, + $ccl_errpos); ok($res == 0, "created CCL2RPN query"); check_record($conn, $q); Net::Z3950::ZOOM::query_destroy($q); diff --git a/t/15-scan.t b/t/15-scan.t index cc8a75f..485825b 100644 --- a/t/15-scan.t +++ b/t/15-scan.t @@ -1,4 +1,4 @@ -# $Id: 15-scan.t,v 1.10 2006-06-13 16:44:21 mike Exp $ +# $Id: 15-scan.t,v 1.11 2006-06-15 15:45:48 mike Exp $ # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 15-scan.t' @@ -78,10 +78,10 @@ Net::Z3950::ZOOM::scanset_destroy($ss); ok(1, "destroyed third scanset"); # Now using CCL -Net::Z3950::ZOOM::connection_option_set($conn, cclfile => - "samples/ccl/default.bib"); $q = Net::Z3950::ZOOM::query_create(); -Net::Z3950::ZOOM::query_ccl2rpn($q, 'ti=w', $conn); +my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0); +Net::Z3950::ZOOM::query_ccl2rpn($q, 'ti=w', "ti u=4 s=pw", + $ccl_errcode, $ccl_errstr, $ccl_errpos); ($ss, $n) = scan($conn, 1, $q, 4); # Get last term and use it as seed for next scan $term = Net::Z3950::ZOOM::scanset_term($ss, $n-1, $occ, $len); diff --git a/t/22-query.t b/t/22-query.t index 11a3622..2a56cf8 100644 --- a/t/22-query.t +++ b/t/22-query.t @@ -1,4 +1,4 @@ -# $Id: 22-query.t,v 1.7 2006-06-13 16:14:58 mike Exp $ +# $Id: 22-query.t,v 1.8 2006-06-15 15:43:19 mike Exp $ # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 22-query.t' @@ -87,7 +87,7 @@ ok(1, "[no need to create empty query]"); $conn->option(cqlfile => "samples/cql/pqf.properties"); eval { $q = new ZOOM::Query::CQL2RPN('title=utah and description=epicenter', $conn) }; -ok(!$@, "created CQL2RPN query: \@=$@"); +ok(!$@, "created CQL2RPN query"); check_record($conn, $q); $q->destroy(); @@ -102,7 +102,7 @@ ok($@ && $@->isa("ZOOM::Exception") && ok(1, "[no need to create empty query]"); $conn->option(cclfile => "samples/ccl/default.bib"); eval { $q = new ZOOM::Query::CCL2RPN('ti=utah and ab=epicenter', $conn) }; -ok(!$@, "created CCL2RPN query: \@=$@"); +ok(!$@, "created CCL2RPN query"); check_record($conn, $q); $q->destroy(); -- 1.7.10.4