1 # $Id: ZOOM.pm,v 1.3 2005-10-11 16:23:32 mike Exp $
8 # Member naming convention: hash-element names which begin with an
9 # underscore represent underlying ZOOM-C object descriptors; those
10 # which do not represent Perl's ZOOM objects. (The same convention is
11 # used in naming local variables.)
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.
18 # To get at the underlying ZOOM-C connection object of a result-set
19 # (if you ever needed to do such a thing, which you probably don't)
20 # you'd use $rs->{conn}->_conn().
22 # ----------------------------------------------------------------------------
24 package ZOOM::Exception;
28 my($code, $message, $addinfo) = @_;
44 return $this->message();
49 return $this->addinfo();
53 # ----------------------------------------------------------------------------
55 package ZOOM::Connection;
59 my($host, $port) = @_;
61 my $_conn = Net::Z3950::ZOOM::connection_new($host, $port);
62 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
63 $errcode = Net::Z3950::ZOOM::connection_error($_conn, $errmsg, $addinfo);
64 die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
73 # PRIVATE within this class
77 return $this->{_conn};
82 my($key, $value) = @_;
84 Net::Z3950::ZOOM::connection_option_set($this->_conn(), $key, $value);
91 my $_rs = Net::Z3950::ZOOM::connection_search_pqf($this->_conn(), $query);
92 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
93 $errcode = Net::Z3950::ZOOM::connection_error($this->_conn(),
95 die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
97 return _new ZOOM::ResultSet($this, $query, $_rs);
101 # ----------------------------------------------------------------------------
103 package ZOOM::ResultSet;
107 die "You can't create $class objects directly";
110 # PRIVATE to ZOOM::Connection::search()
113 my($conn, $query, $_rs) = @_;
122 # PRIVATE within this class
132 return Net::Z3950::ZOOM::resultset_size($this->_rs());
139 my $_rec = Net::Z3950::ZOOM::resultset_record($this->_rs(), $which);
140 ### Check for error -- but how?
141 return _new ZOOM::Record($this, $which, $_rec);
145 # ----------------------------------------------------------------------------
147 package ZOOM::Record;
151 die "You can't create $class objects directly";
154 # PRIVATE to ZOOM::ResultSet::record()
157 my($rs, $which, $_rec) = @_;