1 package OpenILS::Utils::ZClient;
2 use UNIVERSAL::require;
4 use overload 'bool' => sub { return $_[0]->{connection} ? 1 : 0 };
6 our $conn_class = 'ZOOM::Connection';
7 our $imp_class = 'ZOOM';
10 # Detect the installed z client, prefering ZOOM.
11 if (!$imp_class->use()) {
13 $imp_class = 'Net::Z3950'; # Try Net::Z3950
14 if ($imp_class->use()) {
16 # Tell 'new' how to build the connection
17 $conn_class = 'Net::Z3950::Connection';
20 die "Cannot load a z39.50 client implementation! Please install either ZOOM or Net::Z3950.\n";
24 # 'new' is called thusly:
25 # my $conn = OpenILS::Utils::ZClient->new( $host, $port, databaseName => $db, user => $username )
31 if ($class ne __PACKAGE__) { # NOT called OO-ishly
32 # put the first param back if called like OpenILS::Utils::ZClient::new()
33 unshift @args, $class;
36 return bless { connection => $conn_class->new(@_) } => __PACKAGE__;
41 my $r = $imp_class eq 'Net::Z3950' ?
42 $self->{connection}->search( @_ ) :
43 $self->{connection}->search_pqf( @_ );
45 return OpenILS::Utils::ZClient::ResultSet->new( $r );
48 *{__PACKAGE__ . '::search_pqf'} = \&search;
53 my $method = $AUTOLOAD;
54 $method =~ s/.*://; # strip fully-qualified portion
56 return $self->{connection}->$method( @_ );
59 #-------------------------------------------------------------------------------
60 package OpenILS::Utils::ZClient::ResultSet;
68 if ($class ne __PACKAGE__) { # NOT called OO-ishly
69 # put the first param back if called like OpenILS::Utils::ZClient::ResultSet::new()
70 unshift @args, $class;
74 return bless { result => $args[0] } => __PACKAGE__;
80 my $r = $imp_class eq 'Net::Z3950' ?
81 $self->{result}->record( ++$offset ) :
82 $self->{result}->record( $offset );
84 return OpenILS::Utils::ZClient::Record->new( $r );
90 my $method = $AUTOLOAD;
91 $method =~ s/.*://; # strip fully-qualified portion
93 return $self->{result}->$method( @_ );
96 #-------------------------------------------------------------------------------
97 package OpenILS::Utils::ZClient::Record;
105 if ($class ne __PACKAGE__) { # NOT called OO-ishly
106 # put the first param back if called like OpenILS::Utils::ZClient::ResultSet::new()
107 unshift @args, $class;
111 return bless { record => shift() } => __PACKAGE__;
116 return $OpenILS::Utils::ZClient::imp_class eq 'Net::Z3950' ?
117 $self->{record}->rawdata( @_ ) :
118 $self->{record}->raw( @_ );
121 *{__PACKAGE__ . '::raw'} = \&rawdata;
126 my $method = $AUTOLOAD;
127 $method =~ s/.*://; # strip fully-qualified portion
129 return $self->{record}->$method( @_ );