Add resolve(), address(), parent(), previous(), next().
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy.pm
index a8ba556..824c6e3 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: IRSpy.pm,v 1.67 2007-02-23 15:01:48 mike Exp $
+# $Id: IRSpy.pm,v 1.71 2007-02-27 14:51:10 mike Exp $
 
 package ZOOM::IRSpy;
 
@@ -132,6 +132,15 @@ sub targets {
 }
 
 
+sub find_targets {
+    my $this = shift();
+    my($query) = @_;
+
+    $this->{allrecords} = 0;    
+    $this->{query} = $query;
+}
+
+
 # Also used by ZOOM::IRSpy::Record
 sub _parse_target_string {
     my($target) = @_;
@@ -179,7 +188,7 @@ sub initialise {
        # access point -- not even 1035 "everywhere" -- so instead we
        # hack together a search that we know will find all records.
        $this->{query} = "port=?*";
-    } else {
+    } elsif ($this->{targets}) {
        # Prepopulate the target map with nulls so that after we fill
        # in what we can from the database query, we know which target
        # IDs we need new records for.
@@ -190,8 +199,10 @@ sub initialise {
 
     $this->log("irspy_debug", "query '", $this->{query}, "'");
     my $rs = $this->{conn}->search(new ZOOM::Query::CQL($this->{query}));
+    $this->log("irspy", "'", $this->{query}, "' found ",
+              $rs->size(), " target records");
     delete $this->{query};     # No longer needed at all
-    $this->log("irspy_debug", "found ", $rs->size(), " target records");
+    my $gatherTargets = !$this->{targets};
     foreach my $i (1 .. $rs->size()) {
        my $target = _render_record($rs, $i-1, "id");
        my $zeerex = _render_record($rs, $i-1, "zeerex");
@@ -199,7 +210,7 @@ sub initialise {
        $target2record{lc($target)} =
            new ZOOM::IRSpy::Record($this, $target, $zeerex);
        push @{ $this->{targets} }, $target
-           if $this->{allrecords};
+           if $gatherTargets;
     }
 
     # Make records for targets not previously in the database
@@ -252,7 +263,8 @@ sub _irspy_to_zeerex {
 
     if ($save_xml) {
        unlink('/tmp/irspy_orig.xml');
-       open FH, '>/tmp/irspy_orig.xml';
+       open FH, '>/tmp/irspy_orig.xml'
+           or die "can't write irspy_orig.xml: $!";
        print FH $irspy_doc->toString();
        close FH;
     }
@@ -260,7 +272,8 @@ sub _irspy_to_zeerex {
     my $result = $this->{irspy_to_zeerex_style}->transform($irspy_doc, %params);
     if ($save_xml) {
        unlink('/tmp/irspy_transformed.xml');
-       open FH, '>/tmp/irspy_transformed.xml';
+       open FH, '>/tmp/irspy_transformed.xml'
+           or die "can't write irspy_transformed.xml: $!";
        print FH $result->toString();
        close FH;
     }
@@ -427,11 +440,13 @@ sub check {
        die "$conn has no current task for event $ev ($evstr)" if !$task;
 
        my $res;
-       eval { $conn->_check() };
-       if ($@) {
+       eval { $conn->check() };
+       if ($@ && ref $@ && $@->isa("ZOOM::Exception")) {
            my $sub = $task->{cb}->{exception};
            die $@ if !defined $sub;
            $res = &$sub($conn, $task, $task->udata(), $@);
+       } elsif ($@) {
+           die "Unexpected non-ZOOM exception: " . ref($@) . " ($@)";
        } else {
            my $sub = $task->{cb}->{$ev};
            if (!defined $sub) {