X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy%2FTask.pm;h=e83552ef1e5a3a91979b7be40e59dbf22b00f92e;hp=7e4d3fbcc2e038ba849c4864c50eaa0582d6958a;hb=00450608fbb1abc4bd5e75d269ff0c87f87b9b48;hpb=68be936d725114cdf77a71c6534ddd16aff94817 diff --git a/lib/ZOOM/IRSpy/Task.pm b/lib/ZOOM/IRSpy/Task.pm index 7e4d3fb..e83552e 100644 --- a/lib/ZOOM/IRSpy/Task.pm +++ b/lib/ZOOM/IRSpy/Task.pm @@ -1,4 +1,3 @@ -# $Id: Task.pm,v 1.3 2006-10-25 10:52:53 mike Exp $ package ZOOM::IRSpy::Task; @@ -6,6 +5,8 @@ use 5.008; use strict; use warnings; +use Scalar::Util; + =head1 NAME ZOOM::IRSpy::Task - base class for tasks in IRSpy @@ -34,7 +35,7 @@ sub new { my $class = shift(); my($conn, $udata, $options, %cb) = @_; - return bless { + my $this = bless { irspy => $conn->{irspy}, conn => $conn, udata => $udata, @@ -42,6 +43,11 @@ sub new { cb => \%cb, timeRegistered => time(), }, $class; + + #Scalar::Util::weaken($this->{irspy}); + #Scalar::Util::weaken($this->{udata}); + + return $this; } @@ -65,14 +71,34 @@ 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 asterisk 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(); - my %options = %{ $this->{options} }; - foreach my $key (sort keys %options) { - my $value = $options{$key}; - $this->conn()->log("irspy_debug", "$this setting option '$key' -> '$value'"); - $this->conn()->option($key, $value); + 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; + } } }