X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Xchat%2FXPI%2FEvents.pm;h=0f120a543e5ed6ef38fe6f2344b530eafe99051d;hb=7e00cc69db0ee7a4379b5378f1673efc4b531ae8;hp=2c753e151e41e9db7b3ada44a97e78300fd10408;hpb=b070e36b8271a2d917f9369af426d5e18cbaa006;p=perl%2Fscripts%2Fxchat.git diff --git a/Xchat/XPI/Events.pm b/Xchat/XPI/Events.pm index 2c753e1..0f120a5 100644 --- a/Xchat/XPI/Events.pm +++ b/Xchat/XPI/Events.pm @@ -3,32 +3,41 @@ package Xchat::XPI::Events; use strict; use warnings; -use Xchat qw/:all/; +use Xchat qw<:all>; use lib get_info 'xchatdir'; -use Xchat::XPI; +use Xchat::XPI::Utils qw; -use constant { - DEFAULT_DELAY => 1000 -}; +use constant DEFAULT_DELAY => 1000; 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, \&_delay_cb, { data => \@_ }; + my $delay = shift; + + if (defined $delay) { + $delay = int $delay; + } else { + $delay = DEFAULT_DELAY; + } + + called_from_script { + hook_timer $delay, \&_delay_cb, { data => \@_ } + } } sub _filter_cb { my @args = @{$_[0]}; my ($cb, $to) = @{$_[1]}; + if ($cb->(@args)) { emit_print $to, @args; return EAT_ALL; @@ -39,15 +48,18 @@ sub _filter_cb { sub filter { my $from = shift; - return hook_print $from, \&_filter_cb, { data => \@_ }; + + called_from_script { + 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 ];