+
+# PRIVATE to this class
+sub _rec {
+ my $this = shift();
+
+ my $_rec = $this->{_rec};
+ die "{_rec} undefined: has this Record been destroy()ed?"
+ if !defined $_rec;
+
+ return $_rec;
+}
+
+sub error {
+ my $this = shift();
+
+ my($errcode, $errmsg, $addinfo, $diagset) = (undef, "dummy", "dummy", "d");
+ $errcode = Net::Z3950::ZOOM::record_error($this->_rec(), $errmsg,
+ $addinfo, $diagset);
+
+ return wantarray() ? ($errcode, $errmsg, $addinfo, $diagset) : $errcode;
+}
+
+sub exception {
+ my $this = shift();
+
+ my($errcode, $errmsg, $addinfo, $diagset) = $this->error();
+ return new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset);
+}
+
+
+sub render {
+ my $this = shift();
+
+ return $this->get("render", @_);
+}
+
+sub raw {
+ my $this = shift();
+
+ return $this->get("raw", @_);
+}
+
+sub get {
+ my $this = shift();
+ my($type, $args) = @_;
+
+ $type = "$type;$args" if defined $args;
+ my $len = 0;
+ my $string = Net::Z3950::ZOOM::record_get($this->_rec(), $type, $len);
+ # I don't think we need '$len' at all. ### Probably the Perl-to-C
+ # glue code should use the value of `len' as well as the opaque
+ # data-pointer returned, to ensure that the SV contains all of the
+ # returned data and does not stop at the first NUL character in
+ # binary data. Carefully check the ZOOM_record_get() documentation.
+ return $string;
+}
+
+sub clone {
+ my $this = shift();
+
+ my $raw = Net::Z3950::ZOOM::record_clone($this->_rec())
+ or ZOOM::_oops(ZOOM::Error::CLONE);
+
+ # Arg 1 (rs) is undefined as the new record doesn't belong to an RS
+ return _new ZOOM::Record(undef, undef, $raw);
+}
+
+sub destroy {
+ my $this = shift();
+
+ Net::Z3950::ZOOM::record_destroy($this->_rec());
+ $this->{_rec} = undef;
+}
+
+
+# ----------------------------------------------------------------------------
+
+package ZOOM::ScanSet;
+
+sub new {
+ my $class = shift();
+ die "You can't create $class objects directly";
+}
+
+# PRIVATE to ZOOM::Connection::scan(),
+sub _new {
+ my $class = shift();
+ my($conn, $startterm, $_ss) = @_;
+
+ return bless {
+ conn => $conn,
+ startterm => $startterm,# This is not currently used, which is
+ # just as well since it could be
+ # either a string (when the SS is
+ # created with scan()) or a
+ # ZOOM::Query object (when it's
+ # created with scan1())
+ _ss => $_ss,
+ }, $class;
+}
+
+# PRIVATE to this class
+sub _ss {
+ my $this = shift();
+
+ my $_ss = $this->{_ss};
+ die "{_ss} undefined: has this ScanSet been destroy()ed?"
+ if !defined $_ss;
+
+ return $_ss;
+}
+
+sub option {
+ my $this = shift();
+ my($key, $value) = @_;
+
+ my $oldval = Net::Z3950::ZOOM::scanset_option_get($this->_ss(), $key);
+ Net::Z3950::ZOOM::scanset_option_set($this->_ss(), $key, $value)
+ if defined $value;
+
+ return $oldval;
+}
+
+sub size {
+ my $this = shift();
+
+ return Net::Z3950::ZOOM::scanset_size($this->_ss());
+}
+
+sub term {
+ my $this = shift();
+ my($which) = @_;
+
+ my($occ, $len) = (0, 0);
+ my $term = Net::Z3950::ZOOM::scanset_term($this->_ss(), $which,
+ $occ, $len)
+ or ZOOM::_oops(ZOOM::Error::SCANTERM);
+
+ die "length of term '$term' differs from returned len=$len"
+ if length($term) != $len;
+
+ return ($term, $occ);
+}
+
+sub display_term {
+ my $this = shift();
+ my($which) = @_;
+
+ my($occ, $len) = (0, 0);
+ my $term = Net::Z3950::ZOOM::scanset_display_term($this->_ss(), $which,
+ $occ, $len)
+ or ZOOM::_oops(ZOOM::Error::SCANTERM);
+
+ die "length of display term '$term' differs from returned len=$len"
+ if length($term) != $len;
+
+ return ($term, $occ);
+}
+
+sub destroy {
+ my $this = shift();
+
+ Net::Z3950::ZOOM::scanset_destroy($this->_ss());
+ $this->{_ss} = undef;
+}
+
+
+# ----------------------------------------------------------------------------
+
+package ZOOM::Package;
+
+sub new {
+ my $class = shift();
+ die "You can't create $class objects directly";
+}
+
+# PRIVATE to ZOOM::Connection::package(),
+sub _new {
+ my $class = shift();
+ my($conn, $options, $_p) = @_;
+
+ return bless {
+ conn => $conn,
+ options => $options,
+ _p => $_p,
+ }, $class;
+}
+
+# PRIVATE to this class
+sub _p {
+ my $this = shift();
+
+ my $_p = $this->{_p};
+ die "{_p} undefined: has this Package been destroy()ed?"
+ if !defined $_p;
+
+ return $_p;
+}
+
+sub option {
+ my $this = shift();
+ my($key, $value) = @_;
+
+ my $oldval = Net::Z3950::ZOOM::package_option_get($this->_p(), $key);
+ Net::Z3950::ZOOM::package_option_set($this->_p(), $key, $value)
+ if defined $value;
+
+ return $oldval;
+}
+
+sub send {
+ my $this = shift();
+ my($type) = @_;
+
+ Net::Z3950::ZOOM::package_send($this->_p(), $type);
+ $this->{conn}->_check();
+}
+
+sub destroy {
+ my $this = shift();
+
+ Net::Z3950::ZOOM::package_destroy($this->_p());
+ $this->{_p} = undef;
+}
+
+
+# There follows trivial support for YAZ logging. This is wired out
+# into the Net::Z3950::ZOOM package, and we here provide wrapper
+# functions -- nothing more than aliases, really -- in the ZOOM::Log
+# package. There really is no point in inventing an OO interface.
+#
+# Passing @_ directly to the underlying Net::Z3950::ZOOM::* functions
+# doesn't work, for reasons that I can't begin to fathom, and that
+# don't particularly interest me. Unpacking into scalars and passing
+# those _does_ work, so that's what we do.
+
+package ZOOM::Log;
+
+sub mask_str { my($a) = @_; Net::Z3950::ZOOM::yaz_log_mask_str($a); }
+sub module_level { my($a) = @_; Net::Z3950::ZOOM::yaz_log_module_level($a); }
+sub init { my($a, $b, $c) = @_;
+ Net::Z3950::ZOOM::yaz_log_init($a, $b, $c) }
+sub init_file { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_file($a) }
+sub init_level { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_level($a) }
+sub init_prefix { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_prefix($a) }
+sub time_format { my($a) = @_; Net::Z3950::ZOOM::yaz_log_time_format($a) }
+sub init_max_size { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_max_size($a) }
+
+sub log {
+ my($level, @message) = @_;
+
+ if ($level !~ /^(0x)?\d+$/) {
+ # Assuming its log-level name, we look it up.
+ my $num = module_level($level);
+ ZOOM::_oops(ZOOM::Error::LOGLEVEL, $level)
+ if $num == 0;
+ $level = $num;
+ }
+
+ Net::Z3950::ZOOM::yaz_log($level, join("", @message));
+}
+
+
+1;