1 # $Id: Connection.pm,v 1.16 2007-05-01 16:30:17 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 records");
54 $zeerex = render_record($rs, 0, "zeerex") if $n > 0;
55 $this->{record} = new ZOOM::IRSpy::Record($this, $target, $zeerex);
63 $this->SUPER::destroy(@_);
69 return $this->{irspy};
77 my $old = $this->{record};
78 $this->{record} = $new if defined $new;
86 return $this->{tasks};
94 my $old = $this->{current_task};
96 $this->{current_task} = $new;
97 $this->log("irspy_task", "set current task to $new");
108 my $old = $this->{next_task};
110 $this->{next_task} = $new;
111 $this->log("irspy_task", "set next task to $new");
120 my($level, @msg) = @_;
122 $this->irspy()->log($level, $this->option("host"), " ", @msg);
128 my($udata, $options, %cb) = @_;
130 $this->add_task(new ZOOM::IRSpy::Task::Connect
131 ($this, $udata, $options, %cb));
137 my($qtype, $qstr, $udata, $options, %cb) = @_;
139 #warn "calling $this->irspy_search(", join(", ", @_), ")\n";
140 $this->add_task(new ZOOM::IRSpy::Task::Search
141 ($qtype, $qstr, $this, $udata, $options, %cb));
145 # Wrapper for backwards compatibility
146 sub irspy_search_pqf {
148 return $this->irspy_search("pqf", @_);
152 sub irspy_rs_record {
154 my($rs, $index0, $udata, $options, %cb) = @_;
156 $this->add_task(new ZOOM::IRSpy::Task::Retrieve
157 ($rs, $index0, $this, $udata, $options, %cb));
165 my $tasks = $this->{tasks};
166 $tasks->[-1]->{next} = $task if @$tasks > 0;
168 $this->log("irspy_task", "added task $task");
174 return ref($this) . "(" . $this->option("host") . ")";
177 use overload '""' => \&render;
186 Mike Taylor, E<lt>mike@indexdata.comE<gt>
188 =head1 COPYRIGHT AND LICENSE
190 Copyright (C) 2006 by Index Data ApS.
192 This library is free software; you can redistribute it and/or modify
193 it under the same terms as Perl itself, either Perl version 5.8.7 or,
194 at your option, any later version of Perl 5 you may have available.