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