File: 19_method_exept.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 (54 lines) | stat: -rw-r--r-- 763 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
49
50
51
52
53
54
#!perl

use Test::More tests => 3;

package foo;
use common::sense;
use base qw/Object::Event/;

sub test : event_cb { }

package foo2;
use base qw/foo/;

sub test : event_cb(-1000) { die }

package foo3;
use base qw/foo2/;

sub test : event_cb(1000) { }

package main;
use common::sense;

my $f  = foo3->new;

my $died;
$f->set_exception_cb (sub {
  $died++;
});

$f->test;

ok ($died, "got exception from method");

my $warn;
$SIG{__WARN__} = sub {
   $warn = $_[0];
};
$f->set_exception_cb (sub {
  $f->test;
});

$f->test;

ok ($warn =~ /recursion/, "got exception callback recursion");

$warn = undef;
$f->set_exception_cb (sub {
  $f->event ('test');
});

$f->event ('test');

ok ($warn =~ /recursion/, "got exception callback recursion via event method");