1 # $Id: ZOOM.pm,v 1.4 2005-10-12 09:44:46 mike Exp $
8 # Member naming convention: hash-element names which begin with an
9 # underscore represent underlying ZOOM-C object descriptors; those
10 # which lack them represent Perl's ZOOM objects. (The same convention
11 # is used in naming local variables where appropriate.)
13 # So, for example, the ZOOM::Connection class has an {_conn} element,
14 # which is a pointer to the ZOOM-C Connection object; but the
15 # ZOOM::ResultSet class has a {conn} element, which is a reference to
16 # the Perl-level Connection object by which it was created. (It may
17 # be that we find we have no need for these references, but for now
20 # To get at the underlying ZOOM-C connection object of a result-set
21 # (if you ever needed to do such a thing, which you probably don't)
22 # you'd use $rs->{conn}->_conn().
24 # ----------------------------------------------------------------------------
26 package ZOOM::Exception;
30 my($code, $message, $addinfo) = @_;
46 return $this->message();
51 return $this->addinfo();
55 # ----------------------------------------------------------------------------
57 package ZOOM::Connection;
61 my($host, $port) = @_;
63 my $_conn = Net::Z3950::ZOOM::connection_new($host, $port);
64 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
65 $errcode = Net::Z3950::ZOOM::connection_error($_conn, $errmsg, $addinfo);
66 die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
75 # PRIVATE within this class
79 my $_conn = $this->{_conn};
80 die "{_conn} undefined: has this ResultSet been destroy()ed?"
88 my($key, $value) = @_;
90 my $oldval = Net::Z3950::ZOOM::connection_option_get($this->_conn(), $key);
91 Net::Z3950::ZOOM::connection_option_set($this->_conn(), $key, $value)
101 my $_rs = Net::Z3950::ZOOM::connection_search_pqf($this->_conn(), $query);
102 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
103 $errcode = Net::Z3950::ZOOM::connection_error($this->_conn(),
105 die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
107 return _new ZOOM::ResultSet($this, $query, $_rs);
113 Net::Z3950::ZOOM::connection_destroy($this->_conn());
114 $this->{_conn} = undef;
118 # ----------------------------------------------------------------------------
120 package ZOOM::ResultSet;
124 die "You can't create $class objects directly";
127 # PRIVATE to ZOOM::Connection::search()
130 my($conn, $query, $_rs) = @_;
139 # PRIVATE within this class
143 my $_rs = $this->{_rs};
144 die "{_rs} undefined: has this ResultSet been destroy()ed?"
153 return Net::Z3950::ZOOM::resultset_size($this->_rs());
160 my $_rec = Net::Z3950::ZOOM::resultset_record($this->_rs(), $which);
161 ### Check for error -- but how?
163 # For some reason, I have to use the explicit "->" syntax in order
164 # to invoke the ZOOM::Record constructor here, even though I don't
165 # have to do the same for _new ZOOM::ResultSet above. Weird.
166 return ZOOM::Record->_new($this, $which, $_rec);
172 Net::Z3950::ZOOM::resultset_destroy($this->_rs());
173 $this->{_rs} = undef;
177 # ----------------------------------------------------------------------------
179 package ZOOM::Record;
183 die "You can't create $class objects directly";
186 # PRIVATE to ZOOM::ResultSet::record()
189 my($rs, $which, $_rec) = @_;
198 # PRIVATE within this class
202 return $this->{_rec};
209 my $string = Net::Z3950::ZOOM::record_get($this->_rec(), "render", $len);
210 # I don't think we need '$len' at all. ### Probably the Perl-to-C
211 # glue code should use the value of `len' as well as the opaque
212 # data-pointer returned, to ensure that the SV contains all of the
213 # returned data and does not stop at the first NUL character in
214 # binary data. Carefully check the ZOOM_record_get() documentation.
222 my $string = Net::Z3950::ZOOM::record_get($this->_rec(), "raw", $len);
223 # See comment about $len in render()