397dbeee29037f713464b3350024ea645ae5c6a1
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Task / Search.pm
1 # $Id: Search.pm,v 1.13 2007-03-14 11:56:35 mike Exp $
2
3 package ZOOM::IRSpy::Task::Search;
4
5 use 5.008;
6 use strict;
7 use warnings;
8
9 use ZOOM::IRSpy::Task;
10 our @ISA = qw(ZOOM::IRSpy::Task);
11
12 =head1 NAME
13
14 ZOOM::IRSpy::Task::Search - a searching task for IRSpy
15
16 =head1 SYNOPSIS
17
18  ## to follow
19
20 =head1 DESCRIPTION
21
22  ## to follow
23
24 =cut
25
26 sub new {
27     my $class = shift();
28     my($query) = shift();
29
30     my $this = $class->SUPER::new(@_);
31     $this->{query} = $query;
32     $this->{rs} = undef;
33     return $this;
34 }
35
36 sub run {
37     my $this = shift();
38
39     $this->set_options();
40
41     my $conn = $this->conn();
42     $conn->connect($conn->option("host"));
43
44     my $query = $this->{query};
45     $this->irspy()->log("irspy_task", $conn->option("host"),
46                         " searching for '$query'");
47     die "task $this has resultset?!" if defined $this->{rs};
48
49     ### Note well that when this task runs, it creates a result-set
50     #   object which MUST BE DESTROYED in order to prevent large-scale
51     #   memory leakage.  So when creating a Task::Search, it is the
52     #   APPLICATION'S RESPONSIBILITY to ensure that the callback
53     #   invoked on success OR FAILURE makes arrangements for the set
54     #   to be destroyed.
55     $this->{rs} = $conn->search_pqf($query);
56     warn "no ZOOM-C level events queued by $this"
57         if $conn->is_idle();
58
59     $this->set_options();
60 }
61
62 sub render {
63     my $this = shift();
64     return ref($this) . "(" . $this->{query} . ")";
65 }
66
67 use overload '""' => \&render;
68
69
70 =head1 SEE ALSO
71
72 ZOOM::IRSpy
73
74 =head1 AUTHOR
75
76 Mike Taylor, E<lt>mike@indexdata.comE<gt>
77
78 =head1 COPYRIGHT AND LICENSE
79
80 Copyright (C) 2006 by Index Data ApS.
81
82 This library is free software; you can redistribute it and/or modify
83 it under the same terms as Perl itself, either Perl version 5.8.7 or,
84 at your option, any later version of Perl 5 you may have available.
85
86 =cut
87
88 1;