irspy_connect() and irspy_search_pqf() have new $udata parameter.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Connection.pm
1 # $Id: Connection.pm,v 1.3 2006-10-12 14:35:43 mike Exp $
2
3 package ZOOM::IRSpy::Connection;
4
5 use 5.008;
6 use strict;
7 use warnings;
8
9 use ZOOM;
10 our @ISA = qw(ZOOM::Connection);
11
12 use ZOOM::IRSpy::Task::Connect;
13 use ZOOM::IRSpy::Task::Search;
14
15
16 =head1 NAME
17
18 ZOOM::IRSpy::Connection - ZOOM::Connection subclass with IRSpy functionality
19
20 =head1 DESCRIPTION
21
22 This class provides some additional private data and methods that are
23 used by IRSpy but which would be useless in any other application.
24 Keeping the private data in these objects removes the need for ugly
25 mappings in the IRSpy object itself; adding the methods makes the
26 application code cleaner.
27
28 The constructor takes an additional first argument, a reference to the
29 IRSpy object that it is associated with.
30
31 =cut
32
33 sub create {
34     my $class = shift();
35     my $irspy = shift();
36
37     my $this = $class->SUPER::create(@_);
38     $this->{irspy} = $irspy;
39     $this->{record} = undef;
40     $this->{tasks} = [];
41
42     return $this;
43 }
44
45
46 sub irspy {
47     my $this = shift();
48     return $this->{irspy};
49 }
50
51
52 sub record {
53     my $this = shift();
54     my($new) = @_;
55
56     my $old = $this->{record};
57     $this->{record} = $new if defined $new;
58     return $old;
59 }
60
61
62 sub tasks {
63     my $this = shift();
64
65     return $this->{tasks};
66 }
67
68
69 sub current_task {
70     my $this = shift();
71     my($new) = @_;
72
73     my $old = $this->{current_task};
74     if (defined $new) {
75         $this->{current_task} = $new;
76         $this->log("irspy_debug", "set current task to $new");
77     }
78
79     return $old;
80 }
81
82
83 sub next_task {
84     my $this = shift();
85     my($new) = @_;
86
87     my $old = $this->{next_task};
88     if (defined $new) {
89         $this->{next_task} = $new;
90         $this->log("irspy_debug", "set next task to $new");
91     }
92
93     return $old;
94 }
95
96
97 sub log {
98     my $this = shift();
99     my($level, @msg) = @_;
100
101     $this->irspy()->log($level, $this->option("host"), " ", @msg);
102 }
103
104
105 sub irspy_connect {
106     my $this = shift();
107     my($udata, %cb) = @_;
108
109     my $task = new ZOOM::IRSpy::Task::Connect($this, $udata, %cb);
110     $this->add_task($task);
111     $this->log("irspy", "registered connect()");
112 }
113
114
115 sub irspy_search_pqf {
116     my $this = shift();
117     my($query, $udata, %cb) = @_;
118
119     my $task = new ZOOM::IRSpy::Task::Search($query, $this, $udata, %cb);
120     $this->add_task($task);
121     $this->log("irspy", "registered search_pqf($query)");
122 }
123
124
125 sub add_task {
126     my $this = shift();
127     my($task) = @_;
128
129     my $tasks = $this->{tasks};
130     $tasks->[-1]->{next} = $task if @$tasks > 0;
131     push @$tasks, $task;
132     $this->log("irspy", "added task $task");
133 }
134
135
136 =head1 SEE ALSO
137
138 ZOOM::IRSpy
139
140 =head1 AUTHOR
141
142 Mike Taylor, E<lt>mike@indexdata.comE<gt>
143
144 =head1 COPYRIGHT AND LICENSE
145
146 Copyright (C) 2006 by Index Data ApS.
147
148 This library is free software; you can redistribute it and/or modify
149 it under the same terms as Perl itself, either Perl version 5.8.7 or,
150 at your option, any later version of Perl 5 you may have available.
151
152 =cut
153
154 1;