1 # $Id: Task.pm,v 1.7 2007-08-01 15:11:03 mike Exp $
3 package ZOOM::IRSpy::Task;
13 ZOOM::IRSpy::Task - base class for tasks in IRSpy
17 use ZOOM::IRSpy::Task;
18 package ZOOM::IRSpy::Task::SomeTask;
19 our @ISA = qw(ZOOM::IRSpy::Task);
20 # ... override methods
24 This class provides a base-class from which individual IRSpy task
25 classes can be derived. For example, C<ZOOM::IRSpy::Task::Search>
26 will represent a searching task, carrying with it a query, a pointer
29 The base class provides nothing more exciting than a link to a
30 callback function to be called when the task is complete, and a
31 pointer to the next task to be performed after this.
37 my($conn, $udata, $options, %cb) = @_;
40 irspy => $conn->{irspy},
45 timeRegistered => time(),
48 #Scalar::Util::weaken($this->{irspy});
49 #Scalar::Util::weaken($this->{udata});
57 return $this->{irspy};
67 return $this->{udata};
72 die "can't run base-class task $this";
75 # In general, this sets the Connection's options to what is in the
76 # task's option hash and sets the option-hash entry to the
77 # Connection's old value of the option: this means that calling this
78 # twice restores the state to how it was before. (That's not quite
79 # true as its impossible to unset an option that was previously set:
80 # such options are instead set to the empty string.)
82 # As a special case, options in the task's option-hash whose names
83 # begin with an asterisk are taken to be persistent: they are set into
84 # the Connection (with the leading hash removed) and deleted from the
85 # task's option-hash so that they will NOT be reset the next time this
91 foreach my $key (sort keys %{ $this->{options} }) {
92 my $value = $this->{options}->{$key};
93 my $persistent = ($key =~ s/^\*//);
94 $value = "" if !defined $value;
95 $this->conn()->log("irspy_debug", "$this setting option '$key' -> ",
96 defined $value ? "'$value'" : "undefined");
97 my $old = $this->conn()->option($key, $value);
99 delete $this->{options}->{"*$key"}
101 $this->{options}->{$key} = $old;
108 return "[base-class] " . ref($this);
111 use overload '""' => \&render;
120 Mike Taylor, E<lt>mike@indexdata.comE<gt>
122 =head1 COPYRIGHT AND LICENSE
124 Copyright (C) 2006 by Index Data ApS.
126 This library is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself, either Perl version 5.8.7 or,
128 at your option, any later version of Perl 5 you may have available.