File: 05_multi_signal.t

package info (click to toggle)
libpoe-component-syndicator-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: perl: 669; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,566 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings FATAL => 'all';
use POE;
use Test::More tests => 4;

{
    package MyComponent;

    use strict;
    use warnings FATAL => 'all';
    use POE;
    use Test::More;
    use base 'POE::Component::Syndicator';

    sub spawn {
        my ($package, %args) = @_; 
        my $self = bless \%args, $package;
        $self->_syndicator_init(
            debug         => 1,
            prefix        => 'my_',
            object_states => [
                $self => [qw(shutdown)],
            ],
        );
        return $self;
    }

    sub shutdown {
        my ($self) = $_[OBJECT];
        $self->_syndicator_destroy();
    }
}

my $synd1 = MyComponent->spawn();
my $synd2 = MyComponent->spawn();

POE::Session->create(
    package_states => [
        main => [qw(
            _start
            _shutdown
            my_registered
            my_shutdown
        )],
    ],
);

$poe_kernel->run();

sub _start {
    my ($kernel, $session) = @_[KERNEL, SESSION];
    $kernel->delay('_shutdown', 60, 'Timed out');
    $kernel->signal($kernel, 'SYNDICATOR_REGISTER', $session, 'all');
}

sub my_registered {
    pass('my_registered');
    $_[HEAP]{registered}++;
    if ($_[HEAP]{registered} == 2) {
        $poe_kernel->signal($poe_kernel, 'SYNDICATOR_SHUTDOWN');
    }
}

sub my_shutdown {
    pass('my_shutdown');
    $poe_kernel->yield('_shutdown');
}

sub _shutdown {
    my ($kernel, $error) = @_[KERNEL, ARG0];
    fail($error) if defined $error;

    $kernel->alarm_remove_all();
    $kernel->signal($kernel, 'SYNDICATOR_SHUTDOWN');
}