1 # $Id: Connection.pm,v 1.18 2007-12-12 10:47:21 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);
50 my $rs = $irspy->{conn}->search(new ZOOM::Query::CQL($query));
52 $this->log("irspy", "query '$query' found $n record", $n==1 ? "" : "s");
53 ### More than 1 hit is always an error and indicates duplicate
54 # records in the database; no hits is fine for a new target
55 # being probed for the first time, but not if the connection is
56 # being created as part of an "all known targets" scan.
58 $zeerex = render_record($rs, 0, "zeerex") if $n > 0;
59 $this->{record} = new ZOOM::IRSpy::Record($this, $target, $zeerex);
67 $this->SUPER::destroy(@_);
73 return $this->{irspy};
81 my $old = $this->{record};
82 $this->{record} = $new if defined $new;
90 return $this->{tasks};
98 my $old = $this->{current_task};
100 $this->{current_task} = $new;
101 $this->log("irspy_task", "set current task to $new");
112 my $old = $this->{next_task};
114 $this->{next_task} = $new;
115 $this->log("irspy_task", "set next task to $new");
124 my($level, @msg) = @_;
126 $this->irspy()->log($level, $this->option("host"), " ", @msg);
132 my($udata, $options, %cb) = @_;
134 $this->add_task(new ZOOM::IRSpy::Task::Connect
135 ($this, $udata, $options, %cb));
141 my($qtype, $qstr, $udata, $options, %cb) = @_;
143 #warn "calling $this->irspy_search(", join(", ", @_), ")\n";
144 $this->add_task(new ZOOM::IRSpy::Task::Search
145 ($qtype, $qstr, $this, $udata, $options, %cb));
149 # Wrapper for backwards compatibility
150 sub irspy_search_pqf {
152 return $this->irspy_search("pqf", @_);
156 sub irspy_rs_record {
158 my($rs, $index0, $udata, $options, %cb) = @_;
160 $this->add_task(new ZOOM::IRSpy::Task::Retrieve
161 ($rs, $index0, $this, $udata, $options, %cb));
169 my $tasks = $this->{tasks};
170 $tasks->[-1]->{next} = $task if @$tasks > 0;
172 $this->log("irspy_task", "added task $task");
178 return ref($this) . "(" . $this->option("host") . ")";
181 use overload '""' => \&render;
190 Mike Taylor, E<lt>mike@indexdata.comE<gt>
192 =head1 COPYRIGHT AND LICENSE
194 Copyright (C) 2006 by Index Data ApS.
196 This library is free software; you can redistribute it and/or modify
197 it under the same terms as Perl itself, either Perl version 5.8.7 or,
198 at your option, any later version of Perl 5 you may have available.