2 package ZOOM::IRSpy::Connection;
9 our @ISA = qw(ZOOM::Connection);
11 use ZOOM::IRSpy::Record;
12 use ZOOM::IRSpy::Utils qw(cql_target render_record irspy_identifier2target);
14 use ZOOM::IRSpy::Task::Connect;
15 use ZOOM::IRSpy::Task::Search;
16 use ZOOM::IRSpy::Task::Retrieve;
21 ZOOM::IRSpy::Connection - ZOOM::Connection subclass with IRSpy functionality
25 This class provides some additional private data and methods that are
26 used by IRSpy but which would be useless in any other application.
27 Keeping the private data in these objects removes the need for ugly
28 mappings in the IRSpy object itself; adding the methods makes the
29 application code cleaner.
31 The constructor takes an two additional leading arguments: a reference
32 to the IRSpy object that it is associated with, and the target ID of
42 my $this = $class->SUPER::create(@_);
43 my $target = irspy_identifier2target($id);
44 $this->option(host => $target);
45 $this->{irspy} = $irspy;
48 my $query = cql_target($id);
51 $rs = $irspy->{conn}->search(new ZOOM::Query::CQL($query));
53 # This should be a "can't happen", but junk entries such as
54 # //lucasportal.info/blogs/payday-usa">'</a>night:G<a href="http://lucasportal.info/blogs/payday-usa">'</a>night/Illepeliz
55 # (yes, really) yield BIB-1 diagnostic 108 "Malformed query"
56 warn "registry search for record '$id' had error: '$@' -- skipping";
60 $this->log("irspy", "query '$query' found $n record", $n==1 ? "" : "s");
61 ### More than 1 hit is always an error and indicates duplicate
62 # records in the database; no hits is fine for a new target
63 # being probed for the first time, but not if the connection is
64 # being created as part of an "all known targets" scan.
66 $zeerex = render_record($rs, 0, "zeerex") if $n > 0;
67 $this->{record} = new ZOOM::IRSpy::Record($this, $target, $zeerex);
75 $this->SUPER::destroy(@_);
81 return $this->{irspy};
89 my $old = $this->{record};
90 $this->{record} = $new if defined $new;
98 return $this->{tasks};
106 my $old = $this->{current_task};
108 $this->{current_task} = $new;
109 $this->log("irspy_task", "set current task to $new");
120 my $old = $this->{next_task};
122 $this->{next_task} = $new;
123 $this->log("irspy_task", "set next task to $new");
132 my($level, @msg) = @_;
134 $this->irspy()->log($level, $this->option("host"), " ", @msg);
140 my($udata, $options, %cb) = @_;
142 $this->add_task(new ZOOM::IRSpy::Task::Connect
143 ($this, $udata, $options, %cb));
149 my($qtype, $qstr, $udata, $options, %cb) = @_;
151 #warn "calling $this->irspy_search(", join(", ", @_), ")\n";
152 $this->add_task(new ZOOM::IRSpy::Task::Search
153 ($qtype, $qstr, $this, $udata, $options, %cb));
157 # Wrapper for backwards compatibility
158 sub irspy_search_pqf {
160 return $this->irspy_search("pqf", @_);
164 sub irspy_rs_record {
166 my($rs, $index0, $udata, $options, %cb) = @_;
168 $this->add_task(new ZOOM::IRSpy::Task::Retrieve
169 ($rs, $index0, $this, $udata, $options, %cb));
177 my $tasks = $this->{tasks};
178 $tasks->[-1]->{next} = $task if @$tasks > 0;
180 $this->log("irspy_task", "added task $task");
186 return ref($this) . "(" . $this->option("host") . ")";
189 use overload '""' => \&render;
198 Mike Taylor, E<lt>mike@indexdata.comE<gt>
200 =head1 COPYRIGHT AND LICENSE
202 Copyright (C) 2006 by Index Data ApS.
204 This library is free software; you can redistribute it and/or modify
205 it under the same terms as Perl itself, either Perl version 5.8.7 or,
206 at your option, any later version of Perl 5 you may have available.