X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FTimer.pm;h=281421f08d72394b13c54912d97fbb476d3ae0ba;hb=41beb204d8c619d5929f9b1368972885e1f49965;hp=8969756f550706bb942e7bc3e7c6f2bb93054841;hpb=586cbb347e7639f5575b48572e75140501a109c0;p=spider.git diff --git a/perl/Timer.pm b/perl/Timer.pm index 8969756f..281421f0 100644 --- a/perl/Timer.pm +++ b/perl/Timer.pm @@ -10,9 +10,11 @@ package Timer; -use vars qw(@timerchain); +use vars qw(@timerchain $notimers); +use DXDebug; @timerchain = (); +$notimers = 0; sub new { @@ -22,15 +24,16 @@ sub new my $self = bless { t=>$time + time, proc=>$proc }, $class; $self->{interval} = $time if $recur; push @timerchain, $self; + $notimers++; + dbg('connll', "Timer created ($notimers)"); return $self; } sub del { my $self = shift; - my $old = delete $self->{proc}; + delete $self->{proc}; @timerchain = grep {$_ != $self} @timerchain; - return $old; } sub handler @@ -38,12 +41,18 @@ sub handler my $now = time; # handle things on the timer chain - for (@timerchain) { - if ($now >= $_->{t}) { - &{$_->{proc}}(); - $_->{t} = $now + $_->{interval} if exists $_->{interval}; + my $t; + foreach $t (@timerchain) { + if ($now >= $t->{t}) { + &{$t->{proc}}(); + $t->{t} = $now + $t->{interval} if exists $t->{interval}; } } } +sub DESTROY +{ + dbg('connll', "timer destroyed ($Timer::notimers)"); + $Timer::notimers--; +} 1;