X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;ds=sidebyside;f=Xchat%2FXPI%2FEvents.pm;h=3b3963b32f502359a748ecbd0d26972bdc103b48;hb=HEAD;hp=f387f8ae7e6bc6915caeeda9cf4ea70b1180cc44;hpb=9db5de0ec290fd8b82a9c510e0d627b31e44d9bd;p=perl%2Fscripts%2Fxchat.git diff --git a/Xchat/XPI/Events.pm b/Xchat/XPI/Events.pm index f387f8a..3b3963b 100644 --- a/Xchat/XPI/Events.pm +++ b/Xchat/XPI/Events.pm @@ -6,29 +6,38 @@ use warnings; 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, @args) = @_; + + if (defined $delay) { + $delay = int $delay; + } else { + $delay = DEFAULT_DELAY; + } + + called_from_script { + hook_timer $delay, \&_delay_cb, { data => \@args } + } } sub _filter_cb { my @args = @{$_[0]}; my ($cb, $to) = @{$_[1]}; + if ($cb->(@args)) { emit_print $to, @args; return EAT_ALL; @@ -38,16 +47,19 @@ sub _filter_cb { } sub filter { - my $from = shift; - return hook_print $from, \&_filter_cb, { data => \@_ }; + my ($from, $cb, $to) = @_; + + called_from_script { + hook_print $from, \&_filter_cb, { data => [ $cb, $to ] } + } } use base qw; our @EXPORT = (); our %EXPORT_TAGS = ( - 'funcs' => [ qw ], - 'consts' => [ qw ] + 'funcs' => [ qw ], + 'consts' => [ qw ], ); our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS; $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];