From 5df13a3edac6981828e962afa004005e89bd7d0b Mon Sep 17 00:00:00 2001 From: darthgandalf Date: Sun, 17 Oct 2010 09:27:15 +0000 Subject: [PATCH] Fix modperl timers API. It was pretty difficult to pass arbitrary argument. Needed to generate new sub each time etc. Now CreateTimer gets new named parameter: context. Its value will be passed to given sub as named parameter context. Also as it was hard to use variant of CreateTimer without named params (there's no parameter 'context' there), that variant is gone. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2160 726aef4b-f618-498e-8847-2d620e286838 --- modules/modperl/startup.pl | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index 03c514bd..59439c40 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -368,25 +368,23 @@ sub NV { sub CreateTimer { my $self = shift; my $id = ZNC::Core::CreateUUID; - my ($ctimer, $job); - if (ref($_[0]) eq 'CODE') { - # for those who doesn't want to use named args - $job = shift; - my ($interval, $cycles, $description) = @_; - $ctimer = ZNC::CreatePerlTimer($self->{_cmod}, $interval, $cycles, "perl-timer-$id", $description, $id); - } else { - my %a = @_; - $job = $a{task}; - $ctimer = ZNC::CreatePerlTimer($self->{_cmod}, $a{interval}//10, $a{cycles}//1, "perl-timer-$id", $a{description}//'Just Another Perl Timer', $id); - } - $self->{_ptimers}{$id}{job} = $job; - $self->{_ptimers}{$id}{cobj} = $ctimer; + my %a = @_; + $self->{_ptimers}{$id}{cobj} = ZNC::CreatePerlTimer( + $self->{_cmod}, + $a{interval}//10, + $a{cycles}//1, + "perl-timer-$id", + $a{description}//'Just Another Perl Timer', + $id); + $self->{_ptimers}{$id}{job} = $a{task}; + $self->{_ptimers}{$id}{context} = $a{context}; } sub _CallTimer { my $self = shift; my $id = shift; - &{$self->{_ptimers}{$id}{job}}($self, $self->{_ptimers}{$id}{obj}); + my $t = $self->{_ptimers}{$id}; + &{$t->{job}}($self, context=>$t->{context}, timer=>$t->{cobj}); } sub _RemoveTimer {