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