1 package OpenILS::Utils::ZClient;
2 use UNIVERSAL::require;
4 our $conn_class = 'ZOOM::Connection';
5 our $imp_class = 'ZOOM';
7 # Detect the installed z client, prefering ZOOM.
8 if (!$imp_class->use()) {
10 $imp_class = 'Net::Z3950'; # Try Net::Z3950
11 if ($imp_class->use()) {
13 # Load the modules we're going to modify
14 'Net::Z3950::Connection'->use();
15 'Net::Z3950::ResultSet'->use();
16 'Net::Z3950::Record'->use();
18 # Tell 'new' how to build the connection
19 $conn_class = 'Net::Z3950::Connection';
21 # Now we're going to give Net::Z3950 a ZOOM-ish interface
23 # Move 'record' out of the way ...
24 *{'Net::Z3950::ResultSet::_real_record'} = *{'Net::Z3950::ResultSet::record'};
25 # ... and install a new version using the 0-based ZOOM semantics
26 *{'Net::Z3950::ResultSet::record'} = sub { return shift()->_real_record(shift() - 1); };
28 # Alias 'search' with the ZOOM 'search_pqf' method
29 *{'Net::Z3950::Connection::search_pqf'} = *{'Net::Z3950::Connection::search'};
31 # And finally, alias 'rawdata' with the ZOOM 'raw' method
32 *{'Net::Z3950::Record::raw'} = sub { return shift()->rawdata(@_); }
35 die "Cannot load a z39.50 client implementation! Please install either ZOOM or Net::Z3950.\n";
39 # 'new' is called thusly:
40 # my $conn = OpenILS::Utils::ZClient->new( $host, $port, databaseName => $db, user => $username )
45 if ($class ne __PACKAGE__) { # NOT called OO-ishly
46 # put the first param back if called like OpenILS::Utils::ZClient::new()
47 unshift @args, $class;
50 return $conn_class->new(@_);