irspy_connect() and irspy_seach_pqf() pass their options hashes
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Connection.pm
1 # $Id: Connection.pm,v 1.5 2006-10-25 10:52:04 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_task", "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_task", "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, $options, %cb) = @_;
108
109     my $task = new ZOOM::IRSpy::Task::Connect($this, $udata, $options, %cb);
110     $this->add_task($task);
111 }
112
113
114 sub irspy_search_pqf {
115     my $this = shift();
116     my($query, $udata, $options, %cb) = @_;
117
118     my $task = new ZOOM::IRSpy::Task::Search($query, $this, $udata, $options, %cb);
119     $this->add_task($task);
120 }
121
122
123 sub add_task {
124     my $this = shift();
125     my($task) = @_;
126
127     my $tasks = $this->{tasks};
128     $tasks->[-1]->{next} = $task if @$tasks > 0;
129     push @$tasks, $task;
130     $this->log("irspy_task", "added task $task");
131 }
132
133
134 =head1 SEE ALSO
135
136 ZOOM::IRSpy
137
138 =head1 AUTHOR
139
140 Mike Taylor, E<lt>mike@indexdata.comE<gt>
141
142 =head1 COPYRIGHT AND LICENSE
143
144 Copyright (C) 2006 by Index Data ApS.
145
146 This library is free software; you can redistribute it and/or modify
147 it under the same terms as Perl itself, either Perl version 5.8.7 or,
148 at your option, any later version of Perl 5 you may have available.
149
150 =cut
151
152 1;