File: 05_unreg_rec.t

package info (click to toggle)
libobject-event-perl 1.230-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 1,099; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 837 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!perl

use Test::More tests => 6;

package foo;
use common::sense;

use Object::Event;
$Object::Event::ENABLE_METHODS_DEFAULT = $ENV{OE_METHODS_ENABLE};

our @ISA = qw/Object::Event/;

package main;
use common::sense;

my $f = foo->new;

my $a = 0;
my $b = 0;
$f->reg_cb (
   test => sub {
      my ($f) = @_;

      $a++;

      $f->unreg_me;
      $f->event ('test2');
   },
   test2 => sub {
      my ($f) = @_;
      $b++;
      $f->unreg_me;
   }
);

ok ($f->handles ('test'),  "handles 'test'");
ok ($f->handles ('test2'), "handles 'test2'");

$f->event ('test');
$f->event ('test');
$f->event ('test2');
$f->event ('test2');

ok (!$f->handles ('test'),  "doesn't handle 'test'");
ok (!$f->handles ('test2'), "doesn't handle 'test2'");

is ($a, 1, 'first callback was called once');
is ($b, 1, 'second callback was called once');