1 # $Id: Connection.pm,v 1.19 2007-12-18 11:59:42 mike Exp $
3 package ZOOM::IRSpy::Connection;
10 our @ISA = qw(ZOOM::Connection);
12 use ZOOM::IRSpy::Record;
13 use ZOOM::IRSpy::Utils qw(cql_target render_record irspy_identifier2target);
15 use ZOOM::IRSpy::Task::Connect;
16 use ZOOM::IRSpy::Task::Search;
17 use ZOOM::IRSpy::Task::Retrieve;
22 ZOOM::IRSpy::Connection - ZOOM::Connection subclass with IRSpy functionality
26 This class provides some additional private data and methods that are
27 used by IRSpy but which would be useless in any other application.
28 Keeping the private data in these objects removes the need for ugly
29 mappings in the IRSpy object itself; adding the methods makes the
30 application code cleaner.
32 The constructor takes an two additional leading arguments: a reference
33 to the IRSpy object that it is associated with, and the target ID of
43 my $this = $class->SUPER::create(@_);
44 my $target = irspy_identifier2target($id);
45 $this->option(host => $target);
46 $this->{irspy} = $irspy;
49 my $query = cql_target($id);
52 $rs = $irspy->{conn}->search(new ZOOM::Query::CQL($query));
54 die "registry search for record '$id' had error: '$@'";
57 $this->log("irspy", "query '$query' found $n record", $n==1 ? "" : "s");
58 ### More than 1 hit is always an error and indicates duplicate
59 # records in the database; no hits is fine for a new target
60 # being probed for the first time, but not if the connection is
61 # being created as part of an "all known targets" scan.
63 $zeerex = render_record($rs, 0, "zeerex") if $n > 0;
64 $this->{record} = new ZOOM::IRSpy::Record($this, $target, $zeerex);
72 $this->SUPER::destroy(@_);
78 return $this->{irspy};
86 my $old = $this->{record};
87 $this->{record} = $new if defined $new;
95 return $this->{tasks};
103 my $old = $this->{current_task};
105 $this->{current_task} = $new;
106 $this->log("irspy_task", "set current task to $new");
117 my $old = $this->{next_task};
119 $this->{next_task} = $new;
120 $this->log("irspy_task", "set next task to $new");
129 my($level, @msg) = @_;
131 $this->irspy()->log($level, $this->option("host"), " ", @msg);
137 my($udata, $options, %cb) = @_;
139 $this->add_task(new ZOOM::IRSpy::Task::Connect
140 ($this, $udata, $options, %cb));
146 my($qtype, $qstr, $udata, $options, %cb) = @_;
148 #warn "calling $this->irspy_search(", join(", ", @_), ")\n";
149 $this->add_task(new ZOOM::IRSpy::Task::Search
150 ($qtype, $qstr, $this, $udata, $options, %cb));
154 # Wrapper for backwards compatibility
155 sub irspy_search_pqf {
157 return $this->irspy_search("pqf", @_);
161 sub irspy_rs_record {
163 my($rs, $index0, $udata, $options, %cb) = @_;
165 $this->add_task(new ZOOM::IRSpy::Task::Retrieve
166 ($rs, $index0, $this, $udata, $options, %cb));
174 my $tasks = $this->{tasks};
175 $tasks->[-1]->{next} = $task if @$tasks > 0;
177 $this->log("irspy_task", "added task $task");
183 return ref($this) . "(" . $this->option("host") . ")";
186 use overload '""' => \&render;
195 Mike Taylor, E<lt>mike@indexdata.comE<gt>
197 =head1 COPYRIGHT AND LICENSE
199 Copyright (C) 2006 by Index Data ApS.
201 This library is free software; you can redistribute it and/or modify
202 it under the same terms as Perl itself, either Perl version 5.8.7 or,
203 at your option, any later version of Perl 5 you may have available.