-# $Id: ZOOM.pm,v 1.15 2005-11-08 15:55:45 mike Exp $
+# $Id: ZOOM.pm,v 1.19 2005-11-16 16:48:11 mike Exp $
use strict;
use warnings;
return Net::Z3950::ZOOM::diag_str($code);
}
-### More of the ZOOM::Exception instantiations should use this
sub _oops {
- my($code, $addinfo) = @_;
+ my($code, $addinfo, $diagset) = @_;
- die new ZOOM::Exception($code, diag_str($code), $addinfo);
+ die new ZOOM::Exception($code, diag_str($code), $addinfo, $diagset);
}
# ----------------------------------------------------------------------------
sub new {
my $class = shift();
- my($code, $message, $addinfo) = @_;
- ### support diag-set, too
+ my($code, $message, $addinfo, $diagset) = @_;
return bless {
code => $code,
message => $message,
addinfo => $addinfo,
+ diagset => $diagset || "ZOOM",
}, $class;
}
return $this->{addinfo};
}
+sub diagset {
+ my $this = shift();
+ return $this->{diagset};
+}
+
+sub render {
+ my $this = shift();
+ my $res = "ZOOM error " . $this->code() . ' "' . $this->message() . '"';
+ $res .= ' (addinfo: "' . $this->addinfo() . '")' if $this->addinfo();
+ return $res;
+}
+
+# This means that untrapped exceptions render nicely.
+use overload '""' => \&render;
# ----------------------------------------------------------------------------
my $class = shift();
my($host, $port) = @_;
- my $_conn = Net::Z3950::ZOOM::connection_new($host, $port);
- my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
- $errcode = Net::Z3950::ZOOM::connection_error($_conn, $errmsg, $addinfo);
- die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
-
- return bless {
+ my $_conn = Net::Z3950::ZOOM::connection_new($host, $port || 0);
+ my $conn = bless {
host => $host,
port => $port,
_conn => $_conn,
};
+ $conn->_check();
+ return $conn;
+}
+
+# PRIVATE to this class
+sub _conn {
+ my $this = shift();
+
+ my $_conn = $this->{_conn};
+ die "{_conn} undefined: has this Connection been destroy()ed?"
+ if !defined $_conn;
+
+ return $_conn;
+}
+
+sub _check {
+ my $this = shift();
+
+ my($errcode, $errmsg, $addinfo, $diagset) = (undef, "x", "x", "x");
+ $errcode = Net::Z3950::ZOOM::connection_error_x($this->_conn(), $errmsg,
+ $addinfo, $diagset);
+ die new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset)
+ if $errcode;
}
sub create {
};
}
-# PRIVATE to this class
-sub _conn {
- my $this = shift();
-
- my $_conn = $this->{_conn};
- die "{_conn} undefined: has this Connection been destroy()ed?"
- if !defined $_conn;
-
- return $_conn;
-}
-
sub error_x {
my $this = shift();
return Net::Z3950::ZOOM::connection_addinfo($this->_conn());
}
+sub diagset {
+ my $this = shift();
+ return Net::Z3950::ZOOM::connection_diagset($this->_conn());
+}
+
sub connect {
my $this = shift();
my($host, $port) = @_;
Net::Z3950::ZOOM::connection_connect($this->_conn(), $host, $port);
- my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
- $errcode = Net::Z3950::ZOOM::connection_error($this->_conn(),
- $errmsg, $addinfo);
- die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
+ $this->_check();
# No return value
}
my $_rs = Net::Z3950::ZOOM::connection_search($this->_conn(),
$query->_query());
- my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
- $errcode = Net::Z3950::ZOOM::connection_error($this->_conn(),
- $errmsg, $addinfo);
- die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
-
+ $this->_check();
return _new ZOOM::ResultSet($this, $query, $_rs);
}
my($pqf) = @_;
my $_rs = Net::Z3950::ZOOM::connection_search_pqf($this->_conn(), $pqf);
- my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
- $errcode = Net::Z3950::ZOOM::connection_error($this->_conn(),
- $errmsg, $addinfo);
- die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
-
+ $this->_check();
return _new ZOOM::ResultSet($this, $pqf, $_rs);
}
my($startterm) = @_;
my $_ss = Net::Z3950::ZOOM::connection_scan($this->_conn(), $startterm);
- my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
- $errcode = Net::Z3950::ZOOM::connection_error($this->_conn(),
- $errmsg, $addinfo);
- die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
-
+ $this->_check();
return _new ZOOM::ScanSet($this, $startterm, $_ss);
}
my $raw = Net::Z3950::ZOOM::resultset_records($this->_rs(), $start, $count,
$return_records);
+ ### Why don't we throw an exception if $raw is undefined?
return undef if !defined $raw;
# We need to package up the returned records in ZOOM::Record objects
my $this = shift();
my($sort_type, $sort_spec) = @_;
- Net::Z3950::ZOOM::resultset_sort($this->_rs(), $sort_type, $sort_spec);
- ### There's no way to check for success, as this is a void function
+ return Net::Z3950::ZOOM::resultset_sort1($this->_rs(),
+ $sort_type, $sort_spec);
}
sub destroy {
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();
my($occ, $len) = (0, 0);
my $term = Net::Z3950::ZOOM::scanset_term($this->_ss(), $which,
$occ, $len);
+ ### Throw exception?
return undef if !defined $term;
die "length of term '$term' differs from returned len=$len"
if length($term) != $len;
my($occ, $len) = (0, 0);
my $term = Net::Z3950::ZOOM::scanset_display_term($this->_ss(), $which,
$occ, $len);
+ ### Throw exception?
return undef if !defined $term;
die "length of display term '$term' differs from returned len=$len"
if length($term) != $len;
my($type) = @_;
Net::Z3950::ZOOM::package_send($this->_p(), $type);
- my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
- $errcode = Net::Z3950::ZOOM::connection_error($this->{conn}->_conn(),
- $errmsg, $addinfo);
- die new ZOOM::Exception($errcode, $errmsg, $addinfo) if $errcode;
+ $this->{conn}->_check();
}
sub destroy {