HOE/POE/Event/Signal.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 3 SCAR 16.7
CC
3
Cov
0%
dispatch
12.0
HANDLED
2.0
BEGIN
2.0
CRAP 5.3
1 package POE::Event::Signal;
2  
3 use POE::Kernel;
4 use POE::Event;
5 use base 'POE::Event';
6  
7 use strict;
8 use warnings;
9  
10 our $flag;
11  
12 sub dispatch {
13 my $self = shift;
14  
15 my $kernel = $self->[POE::Event::KERNEL];
16 my $time = $self->[POE::Event::TIME];
17 my $sender = $self->[POE::Event::FROM];
18 my $session = $self->[POE::Event::TO];
19 my $signal = $self->[POE::Event::NAME]; # I think
20 my $args = $self->[POE::Event::ARGS];
21  
22 # Reset the sig_handled flag
23 # $flag = 0; # not thread safe
24 local $flag = 0;
25  
26 # This algorithm is copied pretty much verbatim from POE's Kernel.pm, it's very elegant anyways.
27
28 my @touched_sessions = ($session);
29 my $touched_index = 0;
30 while ($touched_index < @touched_sessions) {
31 my $next_target = $touched_sessions[$touched_index];
32 push @touched_sessions, $kernel->get_children($next_target);
33 $touched_index++;
34 }
35  
36 if (my $signal_watchers = $kernel->[POE::Kernel::KR_SIGNALS()]->{$signal}) {
37 while( $touched_index-- ) {
38 my $target_session = $touched_sessions[$touched_index];
39 if (exists( $signal_watchers->{$target_session} )) {
40 POE::Event->new(
41 $kernel,
42 $time,
43 $sender,
44 $target_session,
45 $signal_watchers->{$target_session}->[1],
46 $args,
47 )->dispatch();
48 }
49 }
50 }
51  
52 foreach my $dead_session (@touched_sessions) {
53 # Sessions go boom
54 }
55
56 # Flag not set? KILL ALL HUMANS.
57 # TODO
58 }
59  
60 sub HANDLED {
61 $flag = 1;
62 }
63  
64 1;