File Coverage

mylib/POE/Session/Hachi.pm
Criterion Covered Total %
statement 29 36 80.5
branch 7 12 58.3
condition 1 3 33.3
subroutine 4 4 100.0
pod n/a
total 41 55 74.5


line stmt bran cond sub pod time code
1             package POE::Session::Hachi;
2              
3 108     108   1319018 use base 'POE::Session';
  108         225  
  108         9660  
4              
5 108     108   548 use Errno qw(ENOSYS);
  108         320  
  108         5247  
6              
7 108     108   460 use strict;
  108         115  
  108         52056  
8              
9             sub _invoke_state {
10 538     538   1247 my ($self, $source_session, $state, $etc, $file, $line, $fromstate) = @_;
11              
12             # Trace the state invocation if tracing is enabled.
13              
14 538 50       3173 if ($self->[POE::Session::SE_OPTIONS]->{+POE::Session::OPT_TRACE}) {
15 0         0 POE::Kernel::_warn(
16             $POE::Kernel::poe_kernel->ID_session_to_id($self),
17             " -> $state (from $file at $line)\n"
18             );
19             }
20              
21             # The desired destination state doesn't exist in this session.
22             # Attempt to redirect the state transition to _default.
23              
24 538 100       1806 unless (exists $self->[POE::Session::SE_STATES]->{$state}) {
25              
26             # There's no _default either; redirection's not happening today.
27             # Drop the state transition event on the floor, and optionally
28             # make some noise about it.
29              
30 7 50       64 unless (exists $self->[POE::Session::SE_STATES]->{+POE::Session::EN_DEFAULT}) {
31 7         22 $! = ENOSYS;
32 7 50 33     48 if ($self->[POE::Session::SE_OPTIONS]->{+POE::Session::OPT_DEFAULT} and $state ne POE::Session::EN_SIGNAL) {
33 0         0 my $loggable_self =
34             $POE::Kernel::poe_kernel->_data_alias_loggable($self);
35 0         0 POE::Kernel::_warn(
36             "a '$state' event was sent from $file at $line to $loggable_self ",
37             "but $loggable_self has neither a handler for it ",
38             "nor one for _default\n"
39             );
40             }
41 7         36 return undef;
42             }
43              
44             # If we get this far, then there's a _default state to redirect
45             # the transition to. Trace the redirection.
46              
47 0 0       0 if ($self->[POE::Session::SE_OPTIONS]->{+POE::Session::OPT_TRACE}) {
48 0         0 POE::Kernel::_warn(
49             $POE::Kernel::poe_kernel->ID_session_to_id($self),
50             " -> $state redirected to _default\n"
51             );
52             }
53              
54             # Transmogrify the original state transition into a corresponding
55             # _default invocation.
56              
57 0         0 $etc = [ $state, $etc ];
58 0         0 $state = POE::Session::EN_DEFAULT;
59             }
60              
61             # If we get this far, then the state can be invoked. So invoke it
62             # already!
63              
64 531         948 local $POE::SESSION = $self;
65 531         25302 local $POE::KERNEL = $POE::Kernel::poe_kernel;
66 531         798 local $POE::HEAP = $self->[POE::Session::SE_NAMESPACE];
67 531         1011 local $POE::STATE = $state;
68 531         565 local $POE::SENDER = $source_session;
69 531         538 local $POE::CALLER_FILE = $file;
70 531         703 local $POE::CALLER_LINE = $line;
71 531         685 local $POE::CALLER_STATE = $fromstate;
72              
73             # Inline states are invoked this way.
74              
75 531 100       1965 if (ref($self->[POE::Session::SE_STATES]->{$state}) eq 'CODE') {
76 228         716 return $self->[POE::Session::SE_STATES]->{$state}->( @$etc );
77             }
78              
79             # Package and object states are invoked this way.
80              
81 303         426 my ($object, $method) = @{$self->[POE::Session::SE_STATES]->{$state}};
  303         1123  
82 303         1665 return $object->$method( @$etc );
83             }
84              
85             1;