X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Xchat%2FXPI%2FEvents.pm;h=f387f8ae7e6bc6915caeeda9cf4ea70b1180cc44;hb=9db5de0ec290fd8b82a9c510e0d627b31e44d9bd;hp=b0211c2bf8927f8d4ede911a6dcfc82df298c5d3;hpb=d0506fe825279c4658116b8b09fabf51f943a8cd;p=perl%2Fscripts%2Fxchat.git diff --git a/Xchat/XPI/Events.pm b/Xchat/XPI/Events.pm index b0211c2..f387f8a 100644 --- a/Xchat/XPI/Events.pm +++ b/Xchat/XPI/Events.pm @@ -3,7 +3,7 @@ package Xchat::XPI::Events; use strict; use warnings; -use Xchat qw/:all/; +use Xchat qw<:all>; use lib get_info 'xchatdir'; use Xchat::XPI; @@ -14,40 +14,40 @@ 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/; +use base qw; our @EXPORT = (); our %EXPORT_TAGS = ( - 'funcs' => [ qw/delay filter/ ], - 'consts' => [ qw/DEFAULT_DELAY/ ] + 'funcs' => [ qw ], + 'consts' => [ qw ] ); our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];