[OPEN-ILS-DEV] SPAM: PATCH: Support both Net::Z3950 and ZOOM (take 2)

Dan Scott denials at gmail.com
Sat Jun 2 23:21:08 EDT 2007


Hello:

Mike recently committed the new OpenILS/Utils/ZClient.pm with an
updated OpenILS/Application/Search/Z3950.pm. The ZClient.pm module was
meant to provide an abstraction interface that would support both
Net::Z3950 and ZOOM (building on a previous patch of mine which made
Z3950.pm support ZOOM instead of the deprecated Net::Z3950 module).

Unfortunately, Mike's elegant approach of manipulating the symbol
table didn't actually work for providing Net::Z3950 support. After
some experimentation, the best that I have come up with uses some of
Mike's ZClient.pm with the addition of a few if () statements in
Z3950.pm to make the Z39.50 cataloging support in the staff client
work with either ZOOM or Net::Z3950.

Tested on the Gentoo VMWare image by moving ZOOM out of the way and
installing Net::Z3950, performing the Z39.50 search and grabbing a
record, then restoring ZOOM and performing the Z39.50 search / grab a
record again. Received the same number of results for a simple title
search on "wolves" from LC (899) using either approach, and confirmed
that there were no off-by-one issues by retrieving a known item with
only one hit in LC (title search: "apache derby"). It would be great
for someone else to reproduce these results, but I'm confident that
this works (TM).

Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I have
the right to submit it under the open source license indicated in the
file; or
(b) The contribution is based upon previous work that, to the best of
my knowledge, is covered under an appropriate open source license and
I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under the
same open source license (unless I am permitted to submit under a
different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it; and
(d) In the case of each of (a), (b), or (c), I understand and agree
that this project and the contribution are public and that a record of
the contribution (including all personal information I submit with it,
including my sign-off) is maintained indefinitely and may be
redistributed consistent with this project or the open source license
indicated in the file.

-- 
Dan Scott
Laurentian University

(P.S. I credit the strong play of the Senators tonight for inspiring
me to create this patch. Go Sens go!)
-------------- next part --------------
? Open-ILS/src/perlmods/OpenILS/Application/Search/.Z3950.pm.swp
Index: Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
===================================================================
RCS file: /cvs/ILS/Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm,v
retrieving revision 1.22
diff -c -r1.22 Z3950.pm
*** Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	29 May 2007 02:28:03 -0000	1.22
--- Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm	3 Jun 2007 03:19:23 -0000
***************
*** 184,190 ****
  	$logger->info("z3950: query => $query");
  
  	try {
! 		$results = $connection->search_pqf( $query );
  	} catch Error with { $err = shift; };
  
  	return OpenILS::Event->new(
--- 184,194 ----
  	$logger->info("z3950: query => $query");
  
  	try {
! 		if ($OpenILS::Utils::ZClient::imp_class eq 'Net::Z3950') {
! 			$results = $connection->search( $query );
! 		} else {
! 			$results = $connection->search_pqf( $query );
! 		}
  	} catch Error with { $err = shift; };
  
  	return OpenILS::Event->new(
***************
*** 221,229 ****
  
  	my $tend = $limit + $offset;
  
  	my $end = ($tend <= $count) ? $tend : $count;
  
! 	for($offset..$end - 1) {
  
  		my $err;
  		my $mods;
--- 225,240 ----
  
  	my $tend = $limit + $offset;
  
+ 	if ($OpenILS::Utils::ZClient::imp_class eq 'Net::Z3950') {
+ 		$offset++;
+ 	}
+ 
  	my $end = ($tend <= $count) ? $tend : $count;
+ 	if ($OpenILS::Utils::ZClient::imp_class eq 'ZOOM') {
+ 		$end--;
+ 	}
  
! 	for($offset..$end) {
  
  		my $err;
  		my $mods;
***************
*** 236,242 ****
  		try {
  
  			my $rec	= $results->record($_);
! 			$marc		= MARC::Record->new_from_usmarc($rec->raw());
  			$marcs	= entityize($marc->as_xml_record);
  			my $doc	= XML::LibXML->new->parse_string($marcs);
  			$marcxml = entityize( $doc->documentElement->toString );
--- 247,259 ----
  		try {
  
  			my $rec	= $results->record($_);
! 			my $raw;
! 			if ($OpenILS::Utils::ZClient::imp_class eq 'Net::Z3950') {
! 				$raw = $rec->rawdata();
! 			} else {
! 				$raw = $rec->raw();
! 			}
! 			$marc		= MARC::Record->new_from_usmarc($raw);
  			$marcs	= entityize($marc->as_xml_record);
  			my $doc	= XML::LibXML->new->parse_string($marcs);
  			$marcxml = entityize( $doc->documentElement->toString );
Index: Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm
===================================================================
RCS file: /cvs/ILS/Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm,v
retrieving revision 1.1
diff -c -r1.1 ZClient.pm
*** Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm	28 May 2007 14:49:41 -0000	1.1
--- Open-ILS/src/perlmods/OpenILS/Utils/ZClient.pm	3 Jun 2007 03:19:23 -0000
***************
*** 17,35 ****
  
  		# Tell 'new' how to build the connection
  		$conn_class = 'Net::Z3950::Connection';
! 		
! 		# Now we're going to give Net::Z3950 a ZOOM-ish interface
! 
! 		# Move 'record' out of the way ...
! 		*{'Net::Z3950::ResultSet::_real_record'}  = *{'Net::Z3950::ResultSet::record'};
! 		# ... and install a new version using the 0-based ZOOM semantics
! 		*{'Net::Z3950::ResultSet::record'}  = sub { return shift()->_real_record(shift() - 1); };
! 
! 		# Alias 'search' with the ZOOM 'search_pqf' method
! 		*{'Net::Z3950::Connection::search_pqf'}  = *{'Net::Z3950::Connection::search'};
! 
! 		# And finally, alias 'rawdata' with the ZOOM 'raw' method
! 		*{'Net::Z3950::Record::raw'}  = sub { return shift()->rawdata(@_); }
  
  	} else {
  		die "Cannot load a z39.50 client implementation!  Please install either ZOOM or Net::Z3950.\n";
--- 17,35 ----
  
  		# Tell 'new' how to build the connection
  		$conn_class = 'Net::Z3950::Connection';
! #		
! #		# Now we're going to give Net::Z3950 a ZOOM-ish interface
! #
! #		# Move 'record' out of the way ...
! #		*{'Net::Z3950::ResultSet::_real_record'}  = *{'Net::Z3950::ResultSet::record'};
! #		# ... and install a new version using the 0-based ZOOM semantics
! #		*{'Net::Z3950::ResultSet::record'}  = sub { return shift()->_real_record(shift() - 1); };
! #
! #		# Alias 'search' with the ZOOM 'search_pqf' method
! #		*{'Net::Z3950::Connection::search_pqf'}  = *{'Net::Z3950::Connection::search'};
! #
! #		# And finally, alias 'rawdata' with the ZOOM 'raw' method
! #		*{'Net::Z3950::Record::raw'}  = sub { return shift()->rawdata(@_); }
  
  	} else {
  		die "Cannot load a z39.50 client implementation!  Please install either ZOOM or Net::Z3950.\n";


More information about the Open-ils-dev mailing list