From: Vincent Pit Date: Sun, 15 Aug 2010 09:52:29 +0000 (+0200) Subject: Don't use closures in Xchat::XPI::Events X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=b070e36b8271a2d917f9369af426d5e18cbaa006;p=perl%2Fscripts%2Fxchat.git Don't use closures in Xchat::XPI::Events --- diff --git a/Xchat/XPI/Events.pm b/Xchat/XPI/Events.pm index b0211c2..2c753e1 100644 --- a/Xchat/XPI/Events.pm +++ b/Xchat/XPI/Events.pm @@ -14,32 +14,32 @@ use constant { our $VERSION = '0.04'; +sub _delay_cb { + my ($cb, @args) = @{$_[0]}; + $cb->(@args); + return REMOVE; +}; + sub delay { my $d = shift; $d = (defined $d) ? int $d : DEFAULT_DELAY; - return hook_timer $d, sub { - my ($cb, $data) = @{$_[0]}; - &$cb($data); - return REMOVE; - }, { data => \@_ }; + return hook_timer $d, \&_delay_cb, { data => \@_ }; } -my %reorder; +sub _filter_cb { + my @args = @{$_[0]}; + my ($cb, $to) = @{$_[1]}; + if ($cb->(@args)) { + emit_print $to, @args; + return EAT_ALL; + } else { + return EAT_NONE; + } +} sub filter { - return unless @_ == 3; - not defined and return for @_; - my ($cb, $to) = @_[1, 2]; - return hook_print $_[0], sub { - my @args = @{$_[0]}; - if ($cb->(@args)) { - $reorder{$to}->(@args) if exists $reorder{$to}; - emit_print $to, @args; - return EAT_ALL; - } else { - return EAT_NONE; - } - } + my $from = shift; + return hook_print $from, \&_filter_cb, { data => \@_ }; } use base qw/Exporter/;