From afd4e797383577495b4ce5b4ada0eeff640e75a0 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Wed, 11 Oct 2006 16:46:01 +0000 Subject: [PATCH] new() contructor removed, replaced by create() tasks() simplified, now read-only. Added next_task() get/set method, analogous to current_task() Simplified add_task() Removed start_task() --- lib/ZOOM/IRSpy/Connection.pm | 49 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/ZOOM/IRSpy/Connection.pm b/lib/ZOOM/IRSpy/Connection.pm index 74c24a8..7923893 100644 --- a/lib/ZOOM/IRSpy/Connection.pm +++ b/lib/ZOOM/IRSpy/Connection.pm @@ -1,4 +1,4 @@ -# $Id: Connection.pm,v 1.1 2006-10-06 11:33:07 mike Exp $ +# $Id: Connection.pm,v 1.2 2006-10-11 16:46:01 mike Exp $ package ZOOM::IRSpy::Connection; @@ -30,14 +30,14 @@ IRSpy object that it is associated with. =cut -sub new { +sub create { my $class = shift(); my $irspy = shift(); - my $this = $class->SUPER::new(@_); + my $this = $class->SUPER::create(@_); $this->{irspy} = $irspy; $this->{record} = undef; - $this->{tasks} = undef; + $this->{tasks} = []; return $this; } @@ -61,11 +61,8 @@ sub record { sub tasks { my $this = shift(); - my($new) = @_; - my $old = $this->{tasks}; - $this->{tasks} = $new if defined $new; - return $old; + return $this->{tasks}; } @@ -83,6 +80,20 @@ sub current_task { } +sub next_task { + my $this = shift(); + my($new) = @_; + + my $old = $this->{next_task}; + if (defined $new) { + $this->{next_task} = $new; + $this->log("irspy_debug", "set next task to $new"); + } + + return $old; +} + + sub log { my $this = shift(); my($level, @msg) = @_; @@ -113,29 +124,13 @@ sub add_task { my $this = shift(); my($task) = @_; - my $tasks = $this->tasks(); - if (!defined $tasks) { - $this->tasks([ $task ]); - } else { - $tasks->[-1]->{next} = $task; - push @$tasks, $task; - } - + my $tasks = $this->{tasks}; + $tasks->[-1]->{next} = $task if @$tasks > 0; + push @$tasks, $task; $this->log("irspy", "added task $task"); } -sub start_task { - my $this = shift(); - my($task) = @_; - die "no task defined for " . $this->option("host") - if !defined $task; - - $this->current_task($task); - $task->run(); -} - - =head1 SEE ALSO ZOOM::IRSpy -- 1.7.10.4