| 1 | package Sprocket::Session; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use base qw(POE::Session); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Errno qw(ENOSYS); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 140 | ▶ | sub _invoke_state { | ||||||||||||||||||||||||||
|
Subroutine
_invoke_state: called CC=16 SCAR=31.2
| |||||||||||||||||||||||||||||
| 14 | 140 | my ($self, $source_session, $state, $etc, $file, $line, $fromstate) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Trace the state invocation if tracing is enabled. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 140 | ▶ | if ($self->[POE::Session::SE_OPTIONS]->{+POE::Session::OPT_TRACE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | POE::Kernel::_warn( | |||||||||||||||||||||||||||
| 20 | $POE::Kernel::poe_kernel->ID_session_to_id($self), | ||||||||||||||||||||||||||||
| 21 | " -> $state (from $file at $line)\n" | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # The desired destination state doesn't exist in this session. | ||||||||||||||||||||||||||||
| 26 | # Attempt to redirect the state transition to _default. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 140 | ▶ | unless (exists $self->[POE::Session::SE_STATES]->{$state}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # There's no _default either; redirection's not happening today. | ||||||||||||||||||||||||||||
| 31 | # Drop the state transition event on the floor, and optionally | ||||||||||||||||||||||||||||
| 32 | # make some noise about it. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 44 | ▶ | unless (exists $self->[POE::Session::SE_STATES]->{+POE::Session::EN_DEFAULT}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $! = ENOSYS; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($self->[POE::Session::SE_OPTIONS]->{+POE::Session::OPT_DEFAULT} and $state ne POE::Session::EN_SIGNAL) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->[1]{"default"} and $state ne "_signal"
MC/DC0%0/2
$self->[1]{"default"} and $state ne "_signal"
$self->[1]{"default"}
$state ne "_signal"
Truth table0%0/3
A and B
A= $self->[1]{"default"}B= $state ne "_signal"
| |||||||||||||||||||||||||||||
| 37 | 0 | my $loggable_self = | |||||||||||||||||||||||||||
| 38 | $POE::Kernel::poe_kernel->_data_alias_loggable($self); | ||||||||||||||||||||||||||||
| 39 | 0 | POE::Kernel::_warn( | |||||||||||||||||||||||||||
| 40 | "a '$state' event was sent from $file at $line to $loggable_self ", | ||||||||||||||||||||||||||||
| 41 | "but $loggable_self has neither a handler for it ", | ||||||||||||||||||||||||||||
| 42 | "nor one for _default\n" | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | return undef; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # If we get this far, then there's a _default state to redirect | ||||||||||||||||||||||||||||
| 49 | # the transition to. Trace the redirection. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 44 | ▶ | if ($self->[POE::Session::SE_OPTIONS]->{+POE::Session::OPT_TRACE}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | POE::Kernel::_warn( | |||||||||||||||||||||||||||
| 53 | $POE::Kernel::poe_kernel->ID_session_to_id($self), | ||||||||||||||||||||||||||||
| 54 | " -> $state redirected to _default\n" | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # Transmogrify the original state transition into a corresponding | ||||||||||||||||||||||||||||
| 59 | # _default invocation. ARG1 is copied from $etc so it can't be | ||||||||||||||||||||||||||||
| 60 | # altered from a distance. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 44 | $etc = [ $state, [@$etc] ]; | |||||||||||||||||||||||||||
| 63 | 44 | $state = POE::Session::EN_DEFAULT; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # If we get this far, then the state can be invoked. So invoke it | ||||||||||||||||||||||||||||
| 67 | # already! | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Package and object states are invoked this way. | ||||||||||||||||||||||||||||
| 70 | SWITCH: { | ||||||||||||||||||||||||||||
| 71 | 140 | ▶ | if ( $state eq POE::Session::EN_DEFAULT | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state eq "_default" and $etc->[0] =~ m[^([^\|]+)/(.*)]
MC/DC50%1/2
$state eq "_default" and $etc->[0] =~ m[^([^\|]+)/(.*)]
$state eq "_default"
$etc->[0] =~ m[^([^\|]+)/(.*)]
Truth table66%2/3
A and B
A= $state eq "_default"B= $etc->[0] =~ m[^([^\|]+)/(.*)]
| |||||||||||||||||||||||||||||
| 72 | && ( $etc->[0] =~ m/^([^\|]+)\/(.*)/ ) ) { | ||||||||||||||||||||||||||||
| 73 | 44 | ▶ | last SWITCH unless ( $1 && $2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$1 and $2
MC/DC0%0/2
$1 and $2
$1
$2
Truth table33%1/3
A and B
A= $1B= $2
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 44 | my ( $heap, $nstate ) = ( $1, $2 ); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # does this state exist in this session? | ||||||||||||||||||||||||||||
| 78 | 44 | my $om = $self->[POE::Session::SE_STATES]->{ $nstate }; | |||||||||||||||||||||||||||
| 79 | 44 | ▶ | unless( $om ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 3 | $om = $self->[POE::Session::SE_STATES]->{ POE::Session::EN_DEFAULT }; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 44 | ▶ | last SWITCH unless( $om ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # does this object have this method? | ||||||||||||||||||||||||||||
| 85 | 44 | my ( $object, $method ) = @$om; | |||||||||||||||||||||||||||
| 86 | #last SWITCH unless ( $object->can( $method ) ); | ||||||||||||||||||||||||||||
| 87 | 44 | ▶ | if ( $object->{heap} = $object->{heaps}->{ $heap } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 44 | my $ret; | |||||||||||||||||||||||||||
| 89 | 44 | ▶ | if ( $method eq POE::Session::EN_DEFAULT ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 3 | $method = POE::Session::EN_DEFAULT; | |||||||||||||||||||||||||||
| 91 | $ret = | ||||||||||||||||||||||||||||
| 92 | $object->$method( # package/object (implied) | ||||||||||||||||||||||||||||
| 93 | $self, # session | ||||||||||||||||||||||||||||
| 94 | $POE::Kernel::poe_kernel, # kernel | ||||||||||||||||||||||||||||
| 95 | $object->{heap}, # heap | ||||||||||||||||||||||||||||
| 96 | $nstate, # state | ||||||||||||||||||||||||||||
| 97 | $source_session, # sender | ||||||||||||||||||||||||||||
| 98 | undef, # unused #6 | ||||||||||||||||||||||||||||
| 99 | $file, # caller file name | ||||||||||||||||||||||||||||
| 100 | $line, # caller file line | ||||||||||||||||||||||||||||
| 101 | $fromstate, # caller state | ||||||||||||||||||||||||||||
| 102 | $nstate, # original event | ||||||||||||||||||||||||||||
| 103 | 3 | @{$etc->[1]} # args | |||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||
| 106 | $ret = | ||||||||||||||||||||||||||||
| 107 | $object->$method( # package/object (implied) | ||||||||||||||||||||||||||||
| 108 | $self, # session | ||||||||||||||||||||||||||||
| 109 | $POE::Kernel::poe_kernel, # kernel | ||||||||||||||||||||||||||||
| 110 | $object->{heap}, # heap | ||||||||||||||||||||||||||||
| 111 | $nstate, # state | ||||||||||||||||||||||||||||
| 112 | $source_session, # sender | ||||||||||||||||||||||||||||
| 113 | undef, # unused #6 | ||||||||||||||||||||||||||||
| 114 | $file, # caller file name | ||||||||||||||||||||||||||||
| 115 | $line, # caller file line | ||||||||||||||||||||||||||||
| 116 | $fromstate, # caller state | ||||||||||||||||||||||||||||
| 117 | 41 | @{$etc->[1]} # args | |||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 44 | $object->{heap} = undef; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 44 | return $ret; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # Inline states are invoked this way. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 96 | ▶ | if (ref($self->[POE::Session::SE_STATES]->{$state}) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 33 | return $self->[POE::Session::SE_STATES]->{$state}-> | |||||||||||||||||||||||||||
| 131 | ( undef, # object | ||||||||||||||||||||||||||||
| 132 | $self, # session | ||||||||||||||||||||||||||||
| 133 | $POE::Kernel::poe_kernel, # kernel | ||||||||||||||||||||||||||||
| 134 | $self->[POE::Session::SE_NAMESPACE], # heap | ||||||||||||||||||||||||||||
| 135 | $state, # state | ||||||||||||||||||||||||||||
| 136 | $source_session, # sender | ||||||||||||||||||||||||||||
| 137 | undef, # unused #6 | ||||||||||||||||||||||||||||
| 138 | $file, # caller file name | ||||||||||||||||||||||||||||
| 139 | $line, # caller file line | ||||||||||||||||||||||||||||
| 140 | $fromstate, # caller state | ||||||||||||||||||||||||||||
| 141 | @$etc # args | ||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 63 | my ($object, $method) = @{$self->[POE::Session::SE_STATES]->{$state}}; | |||||||||||||||||||||||||||
| 147 | return | ||||||||||||||||||||||||||||
| 148 | 63 | $object->$method # package/object (implied) | |||||||||||||||||||||||||||
| 149 | ( $self, # session | ||||||||||||||||||||||||||||
| 150 | $POE::Kernel::poe_kernel, # kernel | ||||||||||||||||||||||||||||
| 151 | $self->[POE::Session::SE_NAMESPACE], # heap | ||||||||||||||||||||||||||||
| 152 | $state, # state | ||||||||||||||||||||||||||||
| 153 | $source_session, # sender | ||||||||||||||||||||||||||||
| 154 | undef, # unused #6 | ||||||||||||||||||||||||||||
| 155 | $file, # caller file name | ||||||||||||||||||||||||||||
| 156 | $line, # caller file line | ||||||||||||||||||||||||||||
| 157 | $fromstate, # caller state | ||||||||||||||||||||||||||||
| 158 | @$etc # args | ||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 5 | 1; | |||||||||||||||||||||||||||