From: <dar...@us...> - 2010-10-17 09:27:21
|
Revision: 2160 http://znc.svn.sourceforge.net/znc/?rev=2160&view=rev Author: darthgandalf Date: 2010-10-17 09:27:15 +0000 (Sun, 17 Oct 2010) Log Message: ----------- 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. Modified Paths: -------------- trunk/modules/modperl/startup.pl Modified: trunk/modules/modperl/startup.pl =================================================================== --- trunk/modules/modperl/startup.pl 2010-10-17 08:42:07 UTC (rev 2159) +++ trunk/modules/modperl/startup.pl 2010-10-17 09:27:15 UTC (rev 2160) @@ -368,25 +368,23 @@ 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 { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |