- Fix bug in ZOOM::Connection class code that made the
authormike <mike>
Tue, 10 Oct 2006 16:51:59 +0000 (16:51 +0000)
committermike <mike>
Tue, 10 Oct 2006 16:51:59 +0000 (16:51 +0000)
  difficult to subclass -- when called as
  $class->SUPER::new(@_), the constructor blessed the new
  object into ZOOM::Connection rather than info the subclass.
- ZOOM::Connection::create() may now take either a single
  argument, which is a ZOOM::Options object, or any even
  number of argument (including zero), which are key => value
  pairs of options to set.

lib/ZOOM.pm

index 0e3e583..48af46a 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: ZOOM.pm,v 1.36 2006-10-04 17:15:03 mike Exp $
+# $Id: ZOOM.pm,v 1.37 2006-10-10 16:51:59 mike Exp $
 
 use strict;
 use warnings;
@@ -330,7 +330,7 @@ sub new {
        host => $host,
        port => $port,
        _conn => $_conn,
-    };
+    }, $class;
 
     $conn->_check();
     return $conn;
@@ -359,14 +359,29 @@ sub _check {
 
 sub create {
     my $class = shift();
-    my($options) = @_;
+    my(@options) = @_;
+
+    my $_opts;
+    if (@_ == 1) {
+       $_opts = $_[0]->_opts();
+    } else {
+       $_opts = Net::Z3950::ZOOM::options_create();
+       while (@options >= 2) {
+           my $key = shift(@options);
+           my $val = shift(@options);
+           Net::Z3950::ZOOM::options_set($_opts, $key, $val);
+       }
 
-    my $_conn = Net::Z3950::ZOOM::connection_create($options->_opts());
+       die "Odd number of options specified"
+           if @options;
+    }
+
+    my $_conn = Net::Z3950::ZOOM::connection_create($_opts);
     return bless {
        host => undef,
        port => undef,
        _conn => $_conn,
-    };
+    }, $class;
 }
 
 sub error_x {