X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Xchat%2FXPI%2FEvents.pm;h=0f120a543e5ed6ef38fe6f2344b530eafe99051d;hb=7e00cc69db0ee7a4379b5378f1673efc4b531ae8;hp=bb4eac1efe53d9ac6402ef7ab2738cc0b5a5ea11;hpb=b9c3e00cbf52ff5ddb0d79fd66a6877f6feb508d;p=perl%2Fscripts%2Fxchat.git diff --git a/Xchat/XPI/Events.pm b/Xchat/XPI/Events.pm index bb4eac1..0f120a5 100644 --- a/Xchat/XPI/Events.pm +++ b/Xchat/XPI/Events.pm @@ -3,64 +3,65 @@ 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.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 => \@_ }; + my $delay = shift; + + if (defined $delay) { + $delay = int $delay; + } else { + $delay = DEFAULT_DELAY; + } + + called_from_script { + hook_timer $delay, \&_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; + + 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 ]; -$ph = Xchat::XPI->new( - 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;