]> git.vpit.fr Git - perl/scripts/xchat.git/blob - Xchat/XPI/Events.pm
Don't use closures in Xchat::XPI::Events
[perl/scripts/xchat.git] / Xchat / XPI / Events.pm
1 package Xchat::XPI::Events;
2
3 use strict;
4 use warnings;
5
6 use Xchat qw/:all/;
7
8 use lib get_info 'xchatdir';
9 use Xchat::XPI;
10
11 use constant {
12  DEFAULT_DELAY => 1000
13 };
14
15 our $VERSION = '0.04';
16
17 sub _delay_cb {
18  my ($cb, @args) = @{$_[0]};
19  $cb->(@args);
20  return REMOVE;
21 };
22
23 sub delay {
24  my $d = shift;
25  $d = (defined $d) ? int $d : DEFAULT_DELAY;
26  return hook_timer $d, \&_delay_cb, { data => \@_ };
27 }
28
29 sub _filter_cb {
30  my @args      = @{$_[0]};
31  my ($cb, $to) = @{$_[1]};
32  if ($cb->(@args)) {
33   emit_print $to, @args;
34   return EAT_ALL;
35  } else {
36   return EAT_NONE;
37  }
38 }
39
40 sub filter {
41  my $from = shift;
42  return hook_print $from, \&_filter_cb, { data => \@_ };
43 }
44
45 use base qw/Exporter/;
46
47 our @EXPORT         = ();
48 our %EXPORT_TAGS    = (
49  'funcs'  => [ qw/delay filter/ ],
50  'consts' => [ qw/DEFAULT_DELAY/ ]
51 );
52 our @EXPORT_OK      = map { @$_ } values %EXPORT_TAGS;
53 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
54
55 1;