| 1 | package POE::Component::Generic; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id: Generic.pm 1047 2012-11-30 19:53:13Z fil $ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use POE 0.31; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 21 | ▶ | use POE::Wheel::Run; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 21 | ▶ | use POE::Filter::Line; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 21 | ▶ | use POE::Filter::Reference; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use POE::Component::Generic::Child; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use POE::Component::Generic::Object; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 21 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 21 | ▶ | use Devel::Symdump; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 21 | ▶ | use vars qw($AUTOLOAD $VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 21 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 21 | ▶ | use Scalar::Util qw( reftype blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 21 | $VERSION = '0.1403'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 22 | sub spawn | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=8 SCAR=25.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | my( $package, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | croak "$package needs an even number of parameters" if @args & 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | my $self = $package->new( @args ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | if( $^O eq 'MSWin32' and $self->{alt_fork} and $POE::VERSION < 1.3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$^O eq "MSWin32" and $self->{"alt_fork"} and $POE::VERSION < "1.3"
$^O eq "MSWin32" and $self->{"alt_fork"}
MC/DC0%0/3
$^O eq "MSWin32" and $self->{"alt_fork"} and $POE::VERSION < "1.3"
$^O eq "MSWin32"
$self->{"alt_fork"}
$POE::VERSION < "1.3"
Truth table25%1/4
A and B and C
A= $^O eq "MSWin32"B= $self->{"alt_fork"}C= $POE::VERSION < "1.3"
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | carp "Sorry, alt_fork does not work on MSWin32."; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | delete $self->{alt_fork}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | my $options = $self->{'options'}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | $self->{session_id} = POE::Session->create( | ||||||||||||||||||||||||||||||||||||||||||
| 37 | object_states => [ | ||||||||||||||||||||||||||||||||||||||||||
| 38 | $self => { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 40 | map { $_ => '__request1' } | |||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | ▶ | keys %{$self->{package_map}{ $self->{package} }} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $options and ref $options eq "HASH"
MC/DC0%0/2
defined $options and ref $options eq "HASH"
defined $options
ref $options eq "HASH"
Truth table33%1/3
A and B
A= defined $optionsB= ref $options eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | $self => [ qw(_start _stop shutdown kill _child __request2 | ||||||||||||||||||||||||||||||||||||||||||
| 43 | __wheel_close __wheel_err | ||||||||||||||||||||||||||||||||||||||||||
| 44 | __wheel_out __wheel_stderr | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ( ( defined ( $options ) and ref ( $options ) eq 'HASH' ) ? | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ( options => $options ) : () ), | ||||||||||||||||||||||||||||||||||||||||||
| 50 | )->ID(); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | $self->{debug} | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | ▶ | and warn "$self->{name}: session $self->{session_id} created for $self->{package}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 59 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=28.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | my $package = shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 16 | ▶ | @_ = ( package => $_[0] ) if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 16 | ▶ | croak "$package needs an even number of parameters" if @_ & 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 16 | my %p = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 16 | ▶ | while( my( $k, $v ) = each %p ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 66 | $params{ lc $k } = $v; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 16 | ▶ | unless( $params{package} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | croak "Please specify a package"; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # map of commands to packages | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | $params{package_map} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | # param storage | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | $params{store} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | # request IDs | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 16 | $params{RID} = "REQ000000"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | my $self = bless(\%params, $package); | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | $self->{child_PID} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | ▶ | if( $self->{error} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $rt = reftype $self->{error}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | unless( $rt ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | $self->{error_session} = $poe_kernel->get_active_session; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | elsif( 'HASH' eq $rt ) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | @{ $self }{ qw( error_session error ) } = | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | @{ $self->{error} }{ qw( session event ) }; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | ####### | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 16 | ▶ | if( $self->{on_exit} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my $r = ref $self->{on_exit}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | unless( $r ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->{on_exit} = [ $poe_kernel->get_active_session, $self->{on_exit} ]; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ▶ | elsif( 'ARRAY' eq $r or blessed $self->{on_exit} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
"ARRAY" eq $r or builtin::blessed($self->{"on_exit"})
MC/DC0%0/2
"ARRAY" eq $r or builtin::blessed($self->{"on_exit"})
"ARRAY" eq $r
builtin::blessed($self->{"on_exit"})
Truth table33%1/3
A or B
A= "ARRAY" eq $rB= builtin::blessed($self->{"on_exit"})
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | # POEx::URI is OK. | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | croak "on_exit must be a array reference, not $r"; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | ####### | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | POE::Component::Generic::Child::package_load( $self->{package} ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | $self->__package_register( $self->{package}, { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | methods => delete($self->{methods}), | ||||||||||||||||||||||||||||||||||||||||||
| 117 | callbacks => delete($self->{callbacks}), | ||||||||||||||||||||||||||||||||||||||||||
| 118 | postbacks => delete($self->{postbacks}), | ||||||||||||||||||||||||||||||||||||||||||
| 119 | factories => delete($self->{factories}) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 16 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 16 | ▶ | if( $self->{packages} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | my $pdefs = delete $self->{packages}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | while( my( $class, $pdef ) = each %{ $pdefs } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | $self->__package_register( $class, $pdef ); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 16 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 133 | sub __package_register | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__package_register: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 19 | my( $self, $class, $pdef ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 19 | ▶ | unless( ref $pdef ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->__package_map( $class ); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | elsif( 'ARRAY' eq ref $pdef ) { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->__package_map( $class, $pdef ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 19 | $self->__package_map( $class, $pdef->{methods} ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 19 | $self->__callback_map( $class, $pdef->{callbacks} ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 19 | $self->__postback_map( $class, $pdef->{postbacks} ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 19 | $self->__factory_map( $class, $pdef->{factories} ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # Build a map of all methods => package | ||||||||||||||||||||||||||||||||||||||||||
| 153 | sub __package_map | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 21 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__package_map: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 21 | my( $self, $class, $methods ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 21 | my @methods = $self->__package_methods( $class ); | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 21 | my %OK; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 21 | ▶ | if( $methods ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | @OK{ @$methods } = (1) x @$methods; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 21 | my $map = {}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 21 | foreach my $p ( @methods ) { | |||||||||||||||||||||||||||||||||||||||||
| 167 | 103 | my ($pk,$sub) = $self->__method_map( $p ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 103 | ▶ | next unless $sub; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 82 | ▶ | next if $map->{ $sub }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 71 | ▶ | next if $methods and not $OK{ $sub }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$methods and not $OK{$sub}
MC/DC100%2/2
$methods and not $OK{$sub}
$methods
not $OK{$sub}
Truth table100%3/3
A and not(B)
A= $methodsB= not $OK{$sub}
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 64 | my $o = $p; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 64 | ▶ | if (defined &$o) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 64 | $map->{ $sub } = $pk; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 21 | $self->{package_map}{ $class } = $map; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 182 | sub __method_map | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 108 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__method_map: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 108 | my( $P, $method ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 108 | ($method =~ m/^(.+)\:\:([^\:]+)/); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 108 | my $pk = $1; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 108 | my $sub = $2; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 108 | ▶ | return unless $P->__is_method_name( $pk, $sub ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 87 | return ( $pk, $sub ); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | sub __is_method_name | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 108 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_method_name: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 108 | my( $P, $pk, $sub ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 108 | ▶ | return unless $sub =~ /[^A-Z]$/; # I18N detection of CONSTANTS | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 99 | ▶ | return if $sub =~ m/^_/ or # private and/or protected method | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$sub =~ /^_/ or $sub =~ /(carp|croak|confess|cluck)$/
MC/DC100%2/2
$sub =~ /^_/ or $sub =~ /(carp|croak|confess|cluck)$/
$sub =~ /^_/
$sub =~ /(carp|croak|confess|cluck)$/
Truth table100%3/3
A or B
A= $sub =~ /^_/B= $sub =~ /(carp|croak|confess|cluck)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | $sub =~ m/(carp|croak|confess|cluck)$/; # very common subs | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 87 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # Get a list of all methods from the package | ||||||||||||||||||||||||||||||||||||||||||
| 204 | sub __package_methods | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 35 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__package_methods: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 35 | my( $P, $class ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 35 | my @obj = Devel::Symdump->functions( $class ); | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 35 | my $isa = Symbol::qualify_to_ref( "ISA", $class ); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 35 | foreach my $subpack ( @{ *$isa } ) { | |||||||||||||||||||||||||||||||||||||||||
| 211 | 16 | ▶ | next if $subpack eq 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 12 | push @obj, $P->__package_methods( $subpack ); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # we can't distinguish methods from functions :-/ | ||||||||||||||||||||||||||||||||||||||||||
| 215 | return @obj | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 35 | } | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # POE related object methods | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | sub _start | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start: called CC=13 SCAR=26.1
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 9 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 9 | $self->{session_id} = $_[SESSION]->ID; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | ▶ | if ( $self->{alias} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 7 | $self->{name} = $self->{alias}; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 7 | $kernel->alias_set( $self->{alias} ); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 7 | ▶ | $self->{debug} and warn "$self->{name}: alias is $self->{alias}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | $self->{name} = "poe-generic"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | $kernel->refcount_increment( $self->session_id() => __PACKAGE__ ); | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | $self->{referenced} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | ▶ | my $child_p = $self->{child_package} || 'POE::Component::Generic::Child'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'child_package'} || 'POE::Component::Generic::Child'
MC/DC0%0/1
$self->{'child_package'} || 'POE::Component::Generic::Child'
$self->{'child_package'}
Truth table50%1/2
A
A= $self->{'child_package'}
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | my %prog = ( Program => $self->__subref( $child_p, $self->{name} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 9 | ▶ | if ($self->{alt_fork}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | my $perl = $^X; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | ▶ | $perl = $self->{alt_fork} if -x $self->{alt_fork}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | ▶ | if( $ENV{HARNESS_PERL_SWITCHES} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | $perl .= " $ENV{HARNESS_PERL_SWITCHES}"; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | my $os_quote = ($^O eq 'MSWin32') ? q(") : q('); #" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 5 | %prog = (Program => "$perl -M".ref( $self ) | |||||||||||||||||||||||||||||||||||||||||
| 252 | ." -I".join( ' -I', map quotemeta, @INC ) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | ." -e $os_quote".__PACKAGE__."::process_requests(qq(\Q$child_p\E),qq(\Q$self->{name}\E), 1)$os_quote"); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | $self->{debug} and | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | ▶ | warn "$self->{name}: Launching $prog{Program}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 9 | $self->{wheel} = POE::Wheel::Run->new( | |||||||||||||||||||||||||||||||||||||||||
| 259 | %prog, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | CloseOnCall => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | StdinFilter => POE::Filter::Reference->new(), | ||||||||||||||||||||||||||||||||||||||||||
| 262 | StdoutFilter => POE::Filter::Reference->new(), | ||||||||||||||||||||||||||||||||||||||||||
| 263 | StderrFilter => POE::Filter::Line->new(), | ||||||||||||||||||||||||||||||||||||||||||
| 264 | StdoutEvent => '__wheel_out', | ||||||||||||||||||||||||||||||||||||||||||
| 265 | StderrEvent => '__wheel_stderr', | ||||||||||||||||||||||||||||||||||||||||||
| 266 | ErrorEvent => '__wheel_err', | ||||||||||||||||||||||||||||||||||||||||||
| 267 | CloseEvent => '__wheel_close', | ||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 9 | my $pid = $self->{wheel}->PID; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 9 | my $state = ref( $self )."--child--".$pid; | |||||||||||||||||||||||||||||||||||||||||
| 273 | # NB we don't ever remove this state, but a- it won't be enough to | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # keep the session alive, and b- only one state is created ever anyway | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 9 | $poe_kernel->state( $state, $self, '_child' ); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 9 | $poe_kernel->sig_child( $pid, $state ); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 9 | $self->{child_PID} = $pid; | |||||||||||||||||||||||||||||||||||||||||
| 278 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # Tell the other side to create an object | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 9 | ▶ | $self->{object_options} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"object_options"} ||= []
MC/DC100%1/1
$self->{"object_options"} ||= []
$self->{"object_options"}
Truth table100%2/2
A
A= $self->{"object_options"}
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 9 | ▶ | unless( ref $self->{object_options} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $self->{object_options} = [ $self->{object_options} ] | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | my $new = { req => 'setup', | ||||||||||||||||||||||||||||||||||||||||||
| 286 | debug => $self->{debug}, | ||||||||||||||||||||||||||||||||||||||||||
| 287 | args => $self->{object_options}, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | package => $self->{package}, | ||||||||||||||||||||||||||||||||||||||||||
| 289 | name => $self->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 290 | verbose => $self->{verbose}, | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 9 | ▶ | $new->{size} = $self->{size} if $self->{size}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | ▶ | $self->{debug} and warn "$self->{name}: Ask to create object"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | $self->{wheel}->put( $new ); | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 9 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | # Build the smallest closure possible | ||||||||||||||||||||||||||||||||||||||||||
| 301 | sub __subref | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__subref: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | my( $child_p, $name ) = @_[1,2]; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | return sub { process_requests( $child_p, $name ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | sub _stop | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stop: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 9 | my( $self ) = @_[OBJECT, ARG0]; | |||||||||||||||||||||||||||||||||||||||||
| 310 | $self->{debug} and | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 9 | ▶ | warn "$self->{name}: _stop"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | ###################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # Clean up everything | ||||||||||||||||||||||||||||||||||||||||||
| 316 | sub _done | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_done: called CC=9 SCAR=22.2
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 9 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 9 | ▶ | $self->{debug} and warn "$self->{name}: _done"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 9 | $self->{child_PID} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | # remove the wheel | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 9 | ▶ | if ($self->{wheel}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 9 | ▶ | $self->{debug} and warn "$self->{name}: drop wheel"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 9 | $self->{wheel}->shutdown_stdin; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 9 | delete $self->{wheel}; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 9 | delete $self->{close}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 9 | delete $self->{CHLD}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # remove alias or decrease ref count | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 9 | my @aliases; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 9 | ▶ | if( $self->{referenced} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 9 | ▶ | if ( $self->{alias} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 7 | foreach my $alias ( $poe_kernel->alias_list() ) { | |||||||||||||||||||||||||||||||||||||||||
| 337 | 7 | ▶ | $self->{debug} and warn "$self->{name}: remove alias $alias"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 7 | $poe_kernel->alias_remove( $alias ); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 7 | push @aliases, $alias; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | $poe_kernel->refcount_decrement($self->session_id() => __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 9 | $self->{referenced} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | # Also need to clean up any pending | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 9 | $self->__session_clear; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # Tell the user code about this | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 9 | ▶ | if( $self->{on_exit} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | $poe_kernel->post( @{$self->{on_exit}}, { objects=>\@aliases } ); | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | sub __is_done | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_done: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return 0==$self->{child_PID}; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | sub _close_on | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_on: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 18 | my( $self, $what ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 18 | $self->{$what}++; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 18 | ▶ | if( $self->{close} and $self->{CHLD} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"close"} and $self->{"CHLD"}
MC/DC50%1/2
$self->{"close"} and $self->{"CHLD"}
$self->{"close"}
$self->{"CHLD"}
Truth table66%2/3
A and B
A= $self->{"close"}B= $self->{"CHLD"}
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 9 | $self->_done; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | ###################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # POE request to the parent object | ||||||||||||||||||||||||||||||||||||||||||
| 374 | sub __request1 | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 41 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__request1: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 41 | my ( $self,$state, $sender ) = @_[OBJECT, STATE, SENDER]; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 41 | $self->__request( $sender->ID, $state, @_[ARG0..$#_] ); | |||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | # POE request to a sub-object | ||||||||||||||||||||||||||||||||||||||||||
| 381 | sub __request2 | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__request2: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 5 | my ( $self, $sender ) = @_[OBJECT, SENDER]; | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 5 | $self->__request( $sender->ID, @_[ARG0..$#_] ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | ###################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 390 | # Send request to child process | ||||||||||||||||||||||||||||||||||||||||||
| 391 | sub __request | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 46 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__request: called CC=17 SCAR=29.7
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 46 | my ( $self, $sender, $method, $hash, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 46 | ▶ | warn "$self->{name}: $$: processing request $method\n" if ($self->{debug}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | # Get the arguments | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 46 | ▶ | if (ref( $hash ) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | # shallow copy because we are going to modify this hash | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 46 | $hash = { %{ $hash } }; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | die "Data hash is not a hashref!"; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 46 | ▶ | unless ($self->{wheel}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | warn "$self->{name}: No wheel"; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | # If we have an {event}, it means the user wants *something* back | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 46 | ▶ | if( $hash->{event} and not defined $hash->{wantarray} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$hash->{"event"} and not defined $hash->{"wantarray"}
MC/DC100%2/2
$hash->{"event"} and not defined $hash->{"wantarray"}
$hash->{"event"}
not defined $hash->{"wantarray"}
Truth table100%3/3
A and not(B)
A= $hash->{"event"}B= not defined $hash->{"wantarray"}
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 23 | $hash->{wantarray} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | my $params = { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | event => $hash->{event}, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | wantarray => $hash->{wantarray}, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | session => ($hash->{session}||$sender), | ||||||||||||||||||||||||||||||||||||||||||
| 420 | args => \@args, | ||||||||||||||||||||||||||||||||||||||||||
| 421 | package => ($hash->{package}||$self->{package}) | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 46 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$hash->{'session'} || $sender
$hash->{'package'} || $self->{'package'}
MC/DC0%0/2
$hash->{'session'} || $sender
$hash->{'session'}
$sender
MC/DC0%0/2
$hash->{'package'} || $self->{'package'}
$hash->{'package'}
$self->{'package'}
Truth table66%2/3
A || B
A= $hash->{'session'}B= $sender
Truth table66%2/3
A || B
A= $hash->{'package'}B= $self->{'package'}
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 46 | ▶ | $params->{obj} = $hash->{obj} if $hash->{obj}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 46 | ▶ | if( ref $params->{obj} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $params->{obj} = $params->{obj}->ID; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 46 | ▶ | my $class = $params->{package} || $self->{package}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$params->{'package'} || $self->{'package'}
MC/DC0%0/2
$params->{'package'} || $self->{'package'}
$params->{'package'}
$self->{'package'}
Truth table33%1/3
A || B
A= $params->{'package'}B= $self->{'package'}
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 46 | my $RID = $params->{RID} = $self->{RID}++; | |||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 46 | ▶ | if( $self->{factory_map}{ $method } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 3 | $self->__factory_marshall( $params ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | # param storage | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 46 | ▶ | if ( keys %$hash ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | # id to match in param storage | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 46 | $self->{store}->{$RID} = $hash; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 46 | $hash->{session} = $params->{session}; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 46 | $hash->{package} = $params->{package}; | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | # if we have an event to report to...make sure it stays around | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 46 | ▶ | if ( $hash->{event} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 36 | $self->__session_inc( $hash ); | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 46 | ▶ | if( $self->{callback_map}{$class}{ $method } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | $self->__callback_marshall( $params ); | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 46 | ▶ | if( $self->{postback_map}{$class}{ $method } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 5 | $self->__postback_marshall( $params, $sender ); | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 46 | ▶ | $self->{debug} and warn "$self->{name}: request put"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 46 | $self->{wheel}->put( $params ); | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 46 | return; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | sub __session_inc | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 36 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__session_inc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 36 | my( $self, $hash ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 36 | my $session = $self->__session_id( $hash ); | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 36 | $poe_kernel->refcount_increment( $session => $self->{name} ); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 36 | $self->{pending}{$session}++; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | sub __session_dec | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 36 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__session_dec: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 36 | my( $self, $hash ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 36 | my $session = $self->__session_id( $hash ); | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 36 | ▶ | if( $self->{pending}{$session} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 36 | $poe_kernel->refcount_decrement( $session => $self->{name} ); | |||||||||||||||||||||||||||||||||||||||||
| 477 | 36 | ▶ | delete $self->{pending}{$session} unless $self->{pending}{$session}--; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | sub __session_clear | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__session_clear: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 9 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 484 | 9 | ▶ | foreach my $session ( keys %{ $self->{pending}||{} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'pending'} || {}
MC/DC100%1/1
$self->{'pending'} || {}
$self->{'pending'}
Truth table100%2/2
A
A= $self->{'pending'}
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 9 | ▶ | while( $self->{pending}{$session} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | $self->__session_dec( { session=>$session } ); | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | sub __session_id | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 72 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__session_id: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 72 | my( $self, $hash ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 72 | my $session = $poe_kernel->alias_resolve( $hash->{session} ); | |||||||||||||||||||||||||||||||||||||||||
| 495 | # TODO : Above will explode if $hash->{session} isn't an extant | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # session. This is OK, but the error message will point here, not | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # to the user's code. | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 72 | ▶ | return unless $session; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 72 | return $session->ID; | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 504 | # Prepare the callback definitions | ||||||||||||||||||||||||||||||||||||||||||
| 505 | sub __callback_map | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__callback_map: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 19 | my( $self, $class, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 508 | 19 | ▶ | return unless $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 5 | ▶ | $c = [$c] unless ref $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 5 | my %callbacks; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 5 | @callbacks{ @$c } = map {method=>$_}, @$c; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 5 | $self->{callback_map}{ $class } = \%callbacks; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 520 | # Marshall any callback definitions | ||||||||||||||||||||||||||||||||||||||||||
| 521 | sub __callback_marshall | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__callback_marshall: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 3 | my( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 3 | my $cmap = $self->{callback_map}{ $params->{package} }{ $params->{method} }; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 3 | ▶ | return unless $cmap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 3 | my $args = $params->{args}; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 3 | my @callbacks; | |||||||||||||||||||||||||||||||||||||||||
| 530 | 3 | ▶ | for( my $pos=0; $pos <= $#$args; $pos++ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 8 | ▶ | next unless 'CODE' eq (reftype( $args->[$pos] ) ||''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
builtin::reftype($args->[$pos]) || ''
MC/DC100%1/1
builtin::reftype($args->[$pos]) || ''
builtin::reftype($args->[$pos])
Truth table100%2/2
A
A= builtin::reftype($args->[$pos])
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 4 | my $CBid = "---CALLBACK-$params->{RID}-$pos---"; | |||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | ## the callbacks will be GCed when the method returns, in ->response | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 4 | $self->{callback_defs}{ $params->{RID} }{ $pos } = { | |||||||||||||||||||||||||||||||||||||||||
| 537 | coderef => $args->[$pos] | ||||||||||||||||||||||||||||||||||||||||||
| 538 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 4 | push @callbacks, { CBid=>$CBid, pos=>$pos }; | |||||||||||||||||||||||||||||||||||||||||
| 541 | 4 | $args->[$pos] = $CBid; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 3 | ▶ | return unless @callbacks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 3 | $params->{callbacks} = \@callbacks; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 549 | # Convert a hash-argument into a callback coderef | ||||||||||||||||||||||||||||||||||||||||||
| 550 | sub __callback_argument | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__callback_argument: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my( $self, $event, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $session = $poe_kernel->get_active_session; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | if( $args->{"${event}Event"} ) { # ex: StdoutEvent => 'state' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return $session->postback( $args->{"{event}Event"} ); | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | elsif( $args->{"${event}Sub"} ) { # ex: StdoutSub => sub { } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | return $args->{"${event}Sub"}; | |||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | return undef(); # undef() => not present | |||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 567 | # Prepare the postback definitions | ||||||||||||||||||||||||||||||||||||||||||
| 568 | sub __postback_map | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__postback_map: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 19 | my( $self, $class, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 19 | ▶ | return unless $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | ▶ | $c = {$c => {pos=>0}} unless ref $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | $c = { map { $_ => 0 } @$c } if 'ARRAY' eq ref $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | my %postbacks; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | ▶ | while( my( $method, $pdef ) = each %$c ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 3 | $postbacks{ $method } = { method=>$method, pos=>[] }; | |||||||||||||||||||||||||||||||||||||||||
| 579 | 3 | ▶ | unless( ref $pdef ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | ▶ | $postbacks{ $method }{pos} = [$pdef||0]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$pdef || 0
MC/DC0%0/1
$pdef || 0
$pdef
Truth table50%1/2
A
A= $pdef
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | elsif( 'ARRAY' eq ref $pdef ) { | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 2 | ▶ | $postbacks{ $method }{pos} = [ map { $_||0 } @$pdef ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_ || 0
MC/DC100%1/1
$_ || 0
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | carp "postback position must be an arrayref or scalar"; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | $self->{postback_map}{ $class } = \%postbacks; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 597 | # Marshall any postback definitions | ||||||||||||||||||||||||||||||||||||||||||
| 598 | sub __postback_marshall | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__postback_marshall: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 5 | my( $self, $params, $sender ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 5 | my $pmap = $self->{postback_map}{ $params->{package} }{ $params->{method} }; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 5 | ▶ | return unless $pmap; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 5 | my $args = $params->{args}; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 5 | my @postbacks; | |||||||||||||||||||||||||||||||||||||||||
| 607 | 5 | foreach my $pos ( @{ $pmap->{pos} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 5 | my $PBid = "---POSTBACK-$params->{package}-$pmap->{method}-$pos-$params->{RID}---"; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 5 | push @postbacks, $self->__postback_def( $args->[$pos], $sender, $params->{RID} ); | |||||||||||||||||||||||||||||||||||||||||
| 612 | 5 | $postbacks[-1]->{pos} = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 613 | 5 | $postbacks[-1]->{PBid} = $PBid; | |||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | 5 | $args->[$pos] = $PBid; | |||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||
| 617 | 5 | ▶ | return unless @postbacks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 5 | $params->{postbacks} = \@postbacks; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 623 | sub __postback_def | ||||||||||||||||||||||||||||||||||||||||||
| 624 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__postback_def: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 5 | my( $self, $arg, $sender, $RID ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | 5 | ▶ | unless( ref $arg ) { # simply an event name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 3 | return { event=>$arg, session=>$sender }; | |||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | elsif( 'HASH' eq ref $arg ) { # { event=>'...' } | |||||||||||||||||||||||||||||||||||||||||
| 631 | 2 | ▶ | $arg->{session} ||= $sender; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$arg->{"session"} ||= $sender
MC/DC0%0/2
$arg->{"session"} ||= $sender
$arg->{"session"}
$sender
Truth table33%1/3
A ||= B
A= $arg->{"session"}B= $sender
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 2 | return $arg; | |||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | die "$arg isn't not a valid postback"; | |||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 638 | # Convert a hash-argument into a postback hashref | ||||||||||||||||||||||||||||||||||||||||||
| 639 | sub __postback_argument | ||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__postback_argument: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | my( $self, $event, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | my $session = $poe_kernel->get_active_session; | |||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | ▶ | if( $args->{"${event}Event"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | # ex: StdoutEvent => 'state' | ||||||||||||||||||||||||||||||||||||||||||
| 646 | # or StdoutEvent => { event=>'state', session=>'sessionID'} | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | return $args->{"${event}Event"}; | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | elsif( $args->{"${event}Sub"} ) { # ex: StdoutSub => sub { } | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | croak "${event}Code not supported yet"; | |||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | # Problem : how do we know when to remove the state? | ||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | my $state_name = "SOMETHING"; | |||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $session->state( $state_name => $args->{"{event}Sub"} ); | |||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | return $state_name; | |||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | return undef(); # undef() => not present | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 666 | # Prepare the factory-method definitions | ||||||||||||||||||||||||||||||||||||||||||
| 667 | sub __factory_map | ||||||||||||||||||||||||||||||||||||||||||
| 668 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__factory_map: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 19 | my( $self, $class, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 19 | ▶ | return unless $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 4 | ▶ | $c = {$c => {method=>$c}} unless ref $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | 4 | ▶ | $c = { map { $_ => {method=>$_} } @$c } if 'ARRAY' eq ref $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 4 | my %factories; | |||||||||||||||||||||||||||||||||||||||||
| 675 | 4 | ▶ | @factories{ keys %$c } = map { ref $c->{$_} ? $c->{$_} : {method=>$_} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | keys %$c; | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 4 | $self->{factory_map} = \%factories; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 682 | # Prepare a request for a factory method | ||||||||||||||||||||||||||||||||||||||||||
| 683 | sub __factory_marshall | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__factory_marshall: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 3 | my( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | # tell the remote side it's a special request | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 3 | $params->{factory} = $params->{method}; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 693 | # | ||||||||||||||||||||||||||||||||||||||||||
| 694 | sub __factory_response | ||||||||||||||||||||||||||||||||||||||||||
| 695 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__factory_response: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | 3 | my( $self, $input ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 3 | my $obj_def = $input->{result}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 699 | $input->{result} = [ POE::Component::Generic::Object->new( | ||||||||||||||||||||||||||||||||||||||||||
| 700 | $obj_def, | ||||||||||||||||||||||||||||||||||||||||||
| 701 | $self->session_id, | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 3 | ▶ | $self->{package_map}{ $obj_def->{package}||'' } ) | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$obj_def->{'package'} || ''
MC/DC100%1/1
$obj_def->{'package'} || ''
$obj_def->{'package'}
Truth table100%2/2
A
A= $obj_def->{'package'}
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | ###################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 712 | # Child process sent us a response | ||||||||||||||||||||||||||||||||||||||||||
| 713 | sub __wheel_out | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 54 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__wheel_out: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 54 | my ($self,$input) = @_[ OBJECT,ARG0 ]; | |||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | $self->{debug} and | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 54 | ▶ | warn "$self->{name}: __wheel_out"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 54 | ▶ | $input->{result} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$input->{"result"} ||= []
MC/DC100%1/1
$input->{"result"} ||= []
$input->{"result"}
Truth table100%2/2
A
A= $input->{"result"}
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | 54 | ▶ | if( $input->{response} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 19 | $self->OOB_response( $input ); | |||||||||||||||||||||||||||||||||||||||||
| 724 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 35 | $self->response( $input ); | |||||||||||||||||||||||||||||||||||||||||
| 728 | 35 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | 15 | ▶ | sub __wheel_stderr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__wheel_stderr: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 15 | my ($kernel,$self,$input) = @_[KERNEL,OBJECT,ARG0]; | |||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | warn "$self->{name}:ERR: $input\n" | ||||||||||||||||||||||||||||||||||||||||||
| 735 | 15 | ▶ | if $self->{debug} or $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"debug"} or $self->{"verbose"}
MC/DC0%0/2
$self->{"debug"} or $self->{"verbose"}
$self->{"debug"}
$self->{"verbose"}
Truth table33%1/3
A or B
A= $self->{"debug"}B= $self->{"verbose"}
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | 15 | ▶ | if( $self->{error} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | $poe_kernel->post( $self->{error_session}, $self->{error}, | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 14 | { stderr=>$input } | |||||||||||||||||||||||||||||||||||||||||
| 740 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | 18 | ▶ | sub __wheel_err { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__wheel_err: called CC=6 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||
| 745 | 18 | my ($self, $operation, $errnum, $errstr, $wheel_id) = @_[OBJECT, ARG0..ARG3]; | |||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | warn "$self->{name}: Wheel $wheel_id generated $operation error $errnum: $errstr\n" | ||||||||||||||||||||||||||||||||||||||||||
| 748 | if $self->{debug} or | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 18 | ▶ | ( $self->{verbose} and $errnum != 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$self->{"debug"} or $self->{"verbose"} and $errnum != 0
$self->{"verbose"} and $errnum != 0
MC/DC0%0/3
$self->{"debug"} or $self->{"verbose"} and $errnum != 0
$self->{"debug"}
$self->{"verbose"}
$errnum != 0
Truth table50%2/4
A or B and C
A= $self->{"debug"}B= $self->{"verbose"}C= $errnum != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 750 | 18 | ▶ | if( $errnum!=0 and $self->{error} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$errnum != 0 and $self->{"error"}
MC/DC0%0/2
$errnum != 0 and $self->{"error"}
$errnum != 0
$self->{"error"}
Truth table33%1/3
A and B
A= $errnum != 0B= $self->{"error"}
| |||||||||||||||||||||||||||||||||||||||||||
| 751 | $poe_kernel->post( $self->{error_session}, $self->{error}, | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | { operation => $operation, | |||||||||||||||||||||||||||||||||||||||||
| 753 | errnum => $errnum, | ||||||||||||||||||||||||||||||||||||||||||
| 754 | errstr => $errstr } | ||||||||||||||||||||||||||||||||||||||||||
| 755 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 9 | ▶ | sub __wheel_close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__wheel_close: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | 9 | my $self = $_[OBJECT]; | |||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 9 | ▶ | warn "$self->{name}: Wheel closed\n" if ($self->{debug}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | # We should see a CHLD soon | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 9 | $self->_close_on( 'close' ); | |||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | sub _child | ||||||||||||||||||||||||||||||||||||||||||
| 769 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_child: called CC=5 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | 9 | my( $self, $name, $PID, $ret ) = @_[ OBJECT, ARG0..ARG2 ]; | |||||||||||||||||||||||||||||||||||||||||
| 771 | 9 | ▶ | unless( $PID == ($self->{child_PID}||0) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{'child_PID'} || 0
MC/DC0%0/1
$self->{'child_PID'} || 0
$self->{'child_PID'}
Truth table50%1/2
A
A= $self->{'child_PID'}
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | ▶ | $self->{debug} and warn "$self->{name}: Got CHLD for $PID, not $self->{child_PID}\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||
| 775 | 9 | ▶ | $self->{debug} and warn "$self->{name}: Child $PID exited with $ret"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 9 | $poe_kernel->sig_handled; | |||||||||||||||||||||||||||||||||||||||||
| 777 | 9 | $self->_close_on( 'CHLD' ); | |||||||||||||||||||||||||||||||||||||||||
| 778 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 783 | # | ||||||||||||||||||||||||||||||||||||||||||
| 784 | # Child sent us a response to a {req} request | ||||||||||||||||||||||||||||||||||||||||||
| 785 | sub OOB_response | ||||||||||||||||||||||||||||||||||||||||||
| 786 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
OOB_response: called CC=9 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 787 | 19 | my( $self, $input ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | 19 | my $res = $input->{result}; | |||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | 19 | ▶ | if( $input->{response} eq 'new' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 792 | # $self->{child_PID} = $input->{PID}; | ||||||||||||||||||||||||||||||||||||||||||
| 793 | 8 | ▶ | $self->{debug} and warn "$self->{name}: Child PID=$input->{PID}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||
| 795 | elsif( $input->{response} eq 'callback' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 796 | 6 | my $RID = $input->{RID}; | |||||||||||||||||||||||||||||||||||||||||
| 797 | 6 | my $pos = $input->{pos}; | |||||||||||||||||||||||||||||||||||||||||
| 798 | 6 | my $CB = $self->{callback_defs}{ $RID }{ $pos }; | |||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | 6 | ▶ | unless( $CB ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | warn "$self->{name}: Callback to undefined $RID\[$input->{pos}]"; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||
| 804 | 6 | eval { $CB->{coderef}->( @$res ) }; | |||||||||||||||||||||||||||||||||||||||||
| 805 | 6 | ▶ | warn "$self->{name}: Error in callback: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||
| 807 | elsif( $input->{response} eq 'postback' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 5 | my $PBid = $input->{PBid}; | |||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 5 | ▶ | unless( $input->{session} and $input->{event} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$input->{"session"} and $input->{"event"}
MC/DC0%0/2
$input->{"session"} and $input->{"event"}
$input->{"session"}
$input->{"event"}
Truth table33%1/3
A and B
A= $input->{"session"}B= $input->{"event"}
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | warn "$self->{name}: Bad postback $PBid. Missing {session} or {event}"; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||
| 814 | 5 | $poe_kernel->post( $input->{session} => $input->{event}, @$res ); | |||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||
| 816 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | warn "$self->{name}: Unknown OOB child response $input->{response}"; | |||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 824 | # Child sent us a regular response | ||||||||||||||||||||||||||||||||||||||||||
| 825 | sub response | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 35 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | 35 | my( $self, $input ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 35 | ▶ | if (defined $input->{RID}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | 35 | my $RID = delete $input->{RID}; | |||||||||||||||||||||||||||||||||||||||||
| 831 | # splice in stored data, because we might not trust other side | ||||||||||||||||||||||||||||||||||||||||||
| 832 | 35 | @{ $input }{ keys %{$self->{store}->{$RID}} } | |||||||||||||||||||||||||||||||||||||||||
| 833 | 35 | = values %{$self->{store}->{$RID}}; | |||||||||||||||||||||||||||||||||||||||||
| 834 | 35 | delete $self->{store}->{$RID}; | |||||||||||||||||||||||||||||||||||||||||
| 835 | 35 | delete $self->{callback_defs}->{$RID}; | |||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | 35 | ▶ | if( $input->{factory} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | 3 | $self->__factory_response( $input ); | |||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 35 | my $session = delete $input->{session}; | |||||||||||||||||||||||||||||||||||||||||
| 843 | 35 | my $event = delete $input->{event}; | |||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 35 | ▶ | if ($event) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 35 | ▶ | $self->{debug} and warn "$self->{name}: ($$) Reply to $session/$event"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 847 | 35 | $poe_kernel->post( $session => $event, $input, @{$input->{result}} ); | |||||||||||||||||||||||||||||||||||||||||
| 848 | 35 | $self->__session_dec( {session=>$session} ); | |||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||
| 855 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 856 | # Dual event and object methods | ||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 2 | ▶ | sub kill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kill: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | 2 | ▶ | unless (UNIVERSAL::isa($_[KERNEL],'POE::Kernel')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 861 | 1 | ▶ | if ($poe_kernel and $self->session_id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$POE::Component::Generic::poe_kernel and $self->session_id
MC/DC0%0/2
$POE::Component::Generic::poe_kernel and $self->session_id
$POE::Component::Generic::poe_kernel
$self->session_id
Truth table33%1/3
A and B
A= $POE::Component::Generic::poe_kernelB= $self->session_id
| |||||||||||||||||||||||||||||||||||||||||||
| 862 | 1 | $poe_kernel->call($self->session_id() => 'kill' => @_); | |||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||
| 864 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||
| 867 | 1 | my ($kernel,$self,$sig) = @_[KERNEL,OBJECT,ARG0]; | |||||||||||||||||||||||||||||||||||||||||
| 868 | 1 | ▶ | $self->{debug} and warn "$self->{name}: $self->{wheel}->kill( $sig )"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | 1 | ▶ | return unless $self->{wheel}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 870 | 1 | $self->{wheel}->kill( $sig ); | |||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||
| 873 | 24 | ▶ | sub shutdown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 874 | 24 | ▶ | unless (UNIVERSAL::isa($_[KERNEL],'POE::Kernel')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 876 | 17 | ▶ | if ($poe_kernel and $self->session_id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$POE::Component::Generic::poe_kernel and $self->session_id
MC/DC50%1/2
$POE::Component::Generic::poe_kernel and $self->session_id
$POE::Component::Generic::poe_kernel
$self->session_id
Truth table66%2/3
A and B
A= $POE::Component::Generic::poe_kernelB= $self->session_id
| |||||||||||||||||||||||||||||||||||||||||||
| 877 | 10 | $poe_kernel->call($self->session_id() => 'shutdown' => @_); | |||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 879 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | 7 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | 7 | ▶ | $self->{debug} and warn "$self->{name}: shutdown"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | # if we still have a wheel, tell it to close | ||||||||||||||||||||||||||||||||||||||||||
| 887 | 7 | ▶ | if ($self->{wheel}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 7 | $self->{wheel}->shutdown_stdin; | |||||||||||||||||||||||||||||||||||||||||
| 889 | # this provokes CHLD, which will call ->_done | ||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||
| 891 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 892 | # no wheel; clean up now | ||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | $self->_done; | |||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 7 | undef; | |||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | # Object methods | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | 68 | ▶ | sub session_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
session_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 902 | 68 | shift->{session_id}; | |||||||||||||||||||||||||||||||||||||||||
| 903 | } | ||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | 4 | ▶ | sub yield { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
yield: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 906 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 907 | 4 | $poe_kernel->post($self->session_id() => @_); | |||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | 3 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 912 | 3 | $poe_kernel->call($self->session_id() => @_); | |||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 14 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | $_[0]->{debug} and | ||||||||||||||||||||||||||||||||||||||||||
| 917 | 14 | ▶ | warn "$_[0]->{name}: DESTROY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 918 | 14 | ▶ | if (UNIVERSAL::isa($_[0],__PACKAGE__)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 14 | $_[0]->shutdown(); | |||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | sub AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||
| 924 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=8 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||
| 925 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | 24 | my $method = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 928 | 24 | $method =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | 24 | my $hash; | |||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | 24 | my $bad = ''; | |||||||||||||||||||||||||||||||||||||||||
| 933 | 24 | ▶ | unless( UNIVERSAL::isa( $self, __PACKAGE__ ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | $bad = 'object'; | |||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||
| 936 | elsif( not blessed $self ) { | ||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | $bad = 'package'; | |||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||
| 939 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 940 | 24 | $hash = shift; | |||||||||||||||||||||||||||||||||||||||||
| 941 | 24 | ▶ | unless( ref($hash) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | croak "First argument to $method must be a hashref"; | |||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | 24 | ▶ | unless( $self->{package_map}{ $self->{package} }{ $method } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | $bad = 'object'; | |||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | 24 | ▶ | if( $bad ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | croak qq( Can't locate $bad method "$method" via package ") | |||||||||||||||||||||||||||||||||||||||||
| 952 | .ref( $self ). qq("); #" | ||||||||||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | 24 | ▶ | $hash->{wantarray} = wantarray() unless defined $hash->{wantarray}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||
| 957 | 24 | ▶ | warn "$self->{name}: autoload method $method" if ($self->{debug}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | # use ->call() so that they happen in order | ||||||||||||||||||||||||||||||||||||||||||
| 960 | 24 | $poe_kernel->call( $self->session_id() => $method => $hash => @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||
| 964 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 965 | # Main Wheel::Run process sub | ||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||
| 967 | 4 | ▶ | sub process_requests { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_requests: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 968 | 4 | my( $class, $name, $alt_fork ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 969 | 4 | ▶ | $alt_fork ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$alt_fork ||= 0
MC/DC0%0/1
$alt_fork ||= 0
$alt_fork
Truth table50%1/2
A
A= $alt_fork
| |||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | 4 | my $ID = $name; | |||||||||||||||||||||||||||||||||||||||||
| 972 | 4 | $ID =~ s/\W/-/g; | |||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||
| 974 | 4 | my $runner = $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 975 | name => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 976 | ID => $ID, | ||||||||||||||||||||||||||||||||||||||||||
| 977 | size => 4096, | ||||||||||||||||||||||||||||||||||||||||||
| 978 | debug => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 979 | proc => $0, | ||||||||||||||||||||||||||||||||||||||||||
| 980 | alt_fork => $alt_fork | ||||||||||||||||||||||||||||||||||||||||||
| 981 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 982 | 4 | $runner->loop; | |||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | 21 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||
| 988 | __END__ | ||||||||||||||||||||||||||||||||||||||||||