File: sids.pm

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 (56 lines) | stat: -rw-r--r-- 1,582 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
# vim: ts=2 sw=2 expandtab
use strict;

use lib qw(./mylib ../mylib);
use Test::More tests => 7;

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

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

BEGIN { use_ok("POE") }

# Allocate a session ID.  It starts at 2 because POE::Kernel's virtual
# session has already been allocated.

my $sid = $poe_kernel->_data_sid_allocate();
ok($sid == 1, "first user SID is expected (got $sid)");

# Set an ID for a session.

$poe_kernel->_data_sid_set($sid, "session");

# Ensure that the session ID resolves.

my $resolved_session = $poe_kernel->_data_sid_resolve($sid);
ok($resolved_session eq "session", "session ID resolves correctly");

# Remove the ID from the session.  This relies on a side effect of the
# remove function that returns the removed value.  That may change in
# the future.

my $removed = $poe_kernel->_data_sid_clear($sid);
ok($removed eq "session", "session ID $sid removes $removed correctly");

# What happens if a session doesn't exist?

eval { $poe_kernel->_data_sid_clear("session") };
ok(
  $@ && $@ =~ /unknown SID/,
  "can't clear a sid for a nonexistent session"
);

# POE::Kernel itself has allocated a SID.  Remove that.  This also
# relies on undocumented side effects that can change at any time.

$removed = $poe_kernel->_data_sid_clear($poe_kernel->ID);
ok($removed eq $poe_kernel, "successfully removed POE::Kernel's SID");

# Finalize the subsystem and ensure it shut down cleanly.

ok($poe_kernel->_data_sid_finalize(), "POE::Resource::SIDs finalized ok");

1;