X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy%2FTask.pm;h=8e3f251a26330d543fca904f8046003ddb6b7e7d;hp=e39e18400188c85e738d28f4cd2ad67782a27497;hb=42a6319d3dd983f11a4318e83dce3c02014835f2;hpb=744326399dd931fc8e5360ffa0493f641b91e970 diff --git a/lib/ZOOM/IRSpy/Task.pm b/lib/ZOOM/IRSpy/Task.pm index e39e184..8e3f251 100644 --- a/lib/ZOOM/IRSpy/Task.pm +++ b/lib/ZOOM/IRSpy/Task.pm @@ -1,4 +1,4 @@ -# $Id: Task.pm,v 1.2 2006-10-12 14:36:34 mike Exp $ +# $Id: Task.pm,v 1.7 2007-08-01 15:11:03 mike Exp $ package ZOOM::IRSpy::Task; @@ -32,13 +32,14 @@ pointer to the next task to be performed after this. sub new { my $class = shift(); - my($conn, $udata, %cb) = @_; + my($conn, $udata, $options, %cb) = @_; return bless { irspy => $conn->{irspy}, conn => $conn, - cb => \%cb, udata => $udata, + options => $options, + cb => \%cb, timeRegistered => time(), }, $class; } @@ -64,6 +65,37 @@ sub run { die "can't run base-class task $this"; } +# In general, this sets the Connection's options to what is in the +# task's option hash and sets the option-hash entry to the +# Connection's old value of the option: this means that calling this +# twice restores the state to how it was before. (That's not quite +# true as its impossible to unset an option that was previously set: +# such options are instead set to the empty string.) +# +# As a special case, options in the task's option-hash whose names +# begin with an asterisk are taken to be persistent: they are set into +# the Connection (with the leading hash removed) and deleted from the +# task's option-hash so that they will NOT be reset the next time this +# function is called. +# +sub set_options { + my $this = shift(); + + foreach my $key (sort keys %{ $this->{options} }) { + my $value = $this->{options}->{$key}; + my $persistent = ($key =~ s/^\*//); + $value = "" if !defined $value; + $this->conn()->log("irspy_debug", "$this setting option '$key' -> ", + defined $value ? "'$value'" : "undefined"); + my $old = $this->conn()->option($key, $value); + if ($persistent) { + delete $this->{options}->{"*$key"} + } else { + $this->{options}->{$key} = $old; + } + } +} + sub render { my $this = shift(); return "[base-class] " . ref($this);