File: neyuki_detach.t

package info (click to toggle)
libpoe-perl 2%3A1.3670-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,996 kB
  • ctags: 1,416
  • sloc: perl: 22,865; makefile: 9
file content (100 lines) | stat: -rw-r--r-- 2,133 bytes parent folder | download | duplicates (7)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl -w
# vim: ts=2 sw=2 filetype=perl expandtab

use strict;

use lib qw(./mylib ../mylib);

$| = 1;

sub POE::Kernel::ASSERT_DEFAULT () { 1 }

BEGIN {
  package POE::Kernel;
  use constant TRACE_DEFAULT => exists($INC{'Devel/Cover.pm'});
}

use POE;
use Test::More tests => 8;

my $seq = 0;

POE::Session->create(
  inline_states => {
    _start => sub {
      is(++$seq, 1, "starting parent in sequence");
      $_[KERNEL]->yield('parent');
    },

    _stop => sub {
      # is(++$seq, 8, "stopping parent in sequence");
      undef;
    },

    _parent => sub {
      fail("parent received unexpected _parent");
    },

    _child => sub {
      if ($_[ARG0] eq "create") {
        is(++$seq, 4, "parent received _child create in sequence");
        return;
      }

      if ($_[ARG0] eq "lose") {
        is(++$seq, 6, "parent received _child lose in sequence");
        return;
      }

      fail("parent received unexpected _child $_[ARG0]");
    },

    done => sub {
      # is(++$seq, 8, "parent done in sequence");
      undef;
    },

    parent => sub {
      is(++$seq, 2, "parent spawning child in sequence");

      POE::Session->create(
        inline_states => {
          _start => sub {
            is(++$seq, 3, "child started in sequence");
            $_[KERNEL]->yield('child');
          },

          _stop => sub {
            # is(++$seq, 9, "child stopped in sequence");
            undef;
          },

          _parent => sub {
            is(++$seq, 7, "child received _parent in sequence");
            ok($_[ARG1]->isa("POE::Kernel"), "child parent is POE::Kernel");
          },

          _child => sub {
            fail("child received unexpected _child");
          },

          child => sub {
            is(++$seq, 5, "child detached itself in sequence");

            $_[KERNEL]->detach_myself;
            $_[KERNEL]->yield("done");
          },

          done => sub {
            # is(++$seq, 10, "child is done in sequence");
            undef;
          },
        }
      );

      $_[KERNEL]->yield("done");
    } # parent
  } # inline_states
);

POE::Kernel->run();