Constructor now takes an options-hash argument.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Task.pm
1 # $Id: Task.pm,v 1.3 2006-10-25 10:52:53 mike Exp $
2
3 package ZOOM::IRSpy::Task;
4
5 use 5.008;
6 use strict;
7 use warnings;
8
9 =head1 NAME
10
11 ZOOM::IRSpy::Task - base class for tasks in IRSpy
12
13 =head1 SYNOPSIS
14
15  use ZOOM::IRSpy::Task;
16  package ZOOM::IRSpy::Task::SomeTask;
17  our @ISA = qw(ZOOM::IRSpy::Task);
18  # ... override methods
19
20 =head1 DESCRIPTION
21
22 This class provides a base-class from which individual IRSpy task
23 classes can be derived.  For example, C<ZOOM::IRSpy::Task::Search>
24 will represent a searching task, carrying with it a query, a pointer
25 to a result-set, etc.
26
27 The base class provides nothing more exciting than a link to a
28 callback function to be called when the task is complete, and a
29 pointer to the next task to be performed after this.
30
31 =cut
32
33 sub new {
34     my $class = shift();
35     my($conn, $udata, $options, %cb) = @_;
36
37     return bless {
38         irspy => $conn->{irspy},
39         conn => $conn,
40         udata => $udata,
41         options => $options,
42         cb => \%cb,
43         timeRegistered => time(),
44     }, $class;
45 }
46
47
48 sub irspy {
49     my $this = shift();
50     return $this->{irspy};
51 }
52
53 sub conn {
54     my $this = shift();
55     return $this->{conn};
56 }
57
58 sub udata {
59     my $this = shift();
60     return $this->{udata};
61 }
62
63 sub run {
64     my $this = shift();
65     die "can't run base-class task $this";
66 }
67
68 sub set_options {
69     my $this = shift();
70
71     my %options = %{ $this->{options} };
72     foreach my $key (sort keys %options) {
73         my $value = $options{$key};
74         $this->conn()->log("irspy_debug", "$this setting option '$key' -> '$value'");
75         $this->conn()->option($key, $value);
76     }
77 }
78
79 sub render {
80     my $this = shift();
81     return "[base-class] " . ref($this);
82 }
83
84 use overload '""' => \&render;
85
86
87 =head1 SEE ALSO
88
89 ZOOM::IRSpy
90
91 =head1 AUTHOR
92
93 Mike Taylor, E<lt>mike@indexdata.comE<gt>
94
95 =head1 COPYRIGHT AND LICENSE
96
97 Copyright (C) 2006 by Index Data ApS.
98
99 This library is free software; you can redistribute it and/or modify
100 it under the same terms as Perl itself, either Perl version 5.8.7 or,
101 at your option, any later version of Perl 5 you may have available.
102
103 =cut
104
105 1;