X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Xchat%2FXPI%2FEvents.pm;h=2c753e151e41e9db7b3ada44a97e78300fd10408;hb=b070e36b8271a2d917f9369af426d5e18cbaa006;hp=b26f784ff6e1161b076786e7d7c0a10f16f1f7b5;hpb=263b6777b90548951a13bd56419fa911b010eb9b;p=perl%2Fscripts%2Fxchat.git diff --git a/Xchat/XPI/Events.pm b/Xchat/XPI/Events.pm index b26f784..2c753e1 100644 --- a/Xchat/XPI/Events.pm +++ b/Xchat/XPI/Events.pm @@ -12,36 +12,34 @@ use constant { DEFAULT_DELAY => 1000 }; -our $VERSION = '0.03'; +our $VERSION = '0.04'; -my $ph; +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/; @@ -54,11 +52,4 @@ our %EXPORT_TAGS = ( our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; $EXPORT_TAGS{'all'} = [ @EXPORT_OK ]; -$ph = new Xchat::XPI name => 'Extended Xchat Perl Interface :: Events', - tag => 'XPI::Events', - desc => 'More events handlers', - author => 'Vincent Pit (VPIT)', - email => 'perl@profvince.com', - url => 'http://www.profvince.com'; - 1;