| 1 | package Sprocket::Base; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Sprocket qw( Common Connection Session AIO ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Class::Accessor::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = $Sprocket::VERSION; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | our $sprocket_aio; | |||||||||||||||||||||||||||
| 16 | 5 | our $sprocket; | |||||||||||||||||||||||||||
| 17 | 5 | our $basic_logger = 'Sprocket::Logger::Basic'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | __PACKAGE__->mk_accessors( qw( | |||||||||||||||||||||||||||
| 20 | name | ||||||||||||||||||||||||||||
| 21 | uuid | ||||||||||||||||||||||||||||
| 22 | _uuid | ||||||||||||||||||||||||||||
| 23 | shutting_down | ||||||||||||||||||||||||||||
| 24 | opts | ||||||||||||||||||||||||||||
| 25 | is_forked | ||||||||||||||||||||||||||||
| 26 | is_child | ||||||||||||||||||||||||||||
| 27 | connections | ||||||||||||||||||||||||||||
| 28 | _logger | ||||||||||||||||||||||||||||
| 29 | session_id | ||||||||||||||||||||||||||||
| 30 | ) ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.5
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | eval "use BSD::Resource"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | eval 'sub HAS_BSD_RESOURCE() { '.( $@ ? 0 : 1 ).' }'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # can't use $basic_logger here | ||||||||||||||||||||||||||||
| 37 | 5 | ▶ | eval "use Sprocket::Logger::Basic"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 5 | ▶ | eval 'sub HAS_BASIC_LOGGER() { '.( $@ ? 0 : 1 ).' }'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | $sprocket->register_hook( [qw( | |||||||||||||||||||||||||||
| 41 | sprocket.connection.create | ||||||||||||||||||||||||||||
| 42 | sprocket.connection.destroy | ||||||||||||||||||||||||||||
| 43 | sprocket.plugin.add | ||||||||||||||||||||||||||||
| 44 | sprocket.plugin.remove | ||||||||||||||||||||||||||||
| 45 | )] ); | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # events sent to process_plugins | ||||||||||||||||||||||||||||
| 50 | sub EVENT_NAME() { 0 } | ||||||||||||||||||||||||||||
| 51 | sub SERVER() { 1 } | ||||||||||||||||||||||||||||
| 52 | sub CONNECTION() { 2 } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | our @base_states = qw( | |||||||||||||||||||||||||||
| 55 | _start | ||||||||||||||||||||||||||||
| 56 | _default | ||||||||||||||||||||||||||||
| 57 | signals | ||||||||||||||||||||||||||||
| 58 | shutdown | ||||||||||||||||||||||||||||
| 59 | begin_soft_shutdown | ||||||||||||||||||||||||||||
| 60 | _log | ||||||||||||||||||||||||||||
| 61 | events_received | ||||||||||||||||||||||||||||
| 62 | events_ready | ||||||||||||||||||||||||||||
| 63 | exception | ||||||||||||||||||||||||||||
| 64 | process_plugins | ||||||||||||||||||||||||||||
| 65 | sig_child | ||||||||||||||||||||||||||||
| 66 | time_out_check | ||||||||||||||||||||||||||||
| 67 | cleanup | ||||||||||||||||||||||||||||
| 68 | call_in_ses_context | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 10 | ▶ | sub spawn { | ||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 72 | 10 | my ( $class, $self, @states ) = @_; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # a special session that uses a connection hash | ||||||||||||||||||||||||||||
| 75 | 10 | Sprocket::Session->create( | |||||||||||||||||||||||||||
| 76 | # options => { trace => 1 }, | ||||||||||||||||||||||||||||
| 77 | object_states => [ | ||||||||||||||||||||||||||||
| 78 | $self => [ @base_states, @states ] | ||||||||||||||||||||||||||||
| 79 | ], | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 10 | return $self; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=31.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 10 | my $class = shift; | |||||||||||||||||||||||||||
| 87 | 10 | ▶ | croak "$class requires an even number of parameters" if @_ % 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 10 | my %opts = &adjust_params; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 10 | my $uuid = new_uuid(); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 10 | ▶ | $opts{alias} = "sprocket/$uuid" unless( defined( $opts{alias} ) and length( $opts{alias} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"alias"} and length $opts{"alias"}
MC/DC0%0/2
defined $opts{"alias"} and length $opts{"alias"}
defined $opts{"alias"}
length $opts{"alias"}
Truth table33%1/3
A and B
A= defined $opts{"alias"}B= length $opts{"alias"}
| |||||||||||||||||||||||||||||
| 93 | 10 | ▶ | $opts{name} = "sprocket/$uuid" unless( defined( $opts{name} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 10 | ▶ | $opts{time_out} = defined( $opts{time_out} ) ? $opts{time_out} : 30; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 10 | ▶ | $opts{log_level} = 4 unless( defined( $opts{log_level} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 10 | my $logger = delete $opts{logger}; | |||||||||||||||||||||||||||
| 98 | 10 | ▶ | if ( defined( $logger ) && not UNIVERSAL::can( $logger, 'put' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $logger and not UNIVERSAL::can($logger, "put")
MC/DC0%0/2
defined $logger and not UNIVERSAL::can($logger, "put")
defined $logger
not UNIVERSAL::can($logger, "put")
Truth table33%1/3
A and not(B)
A= defined $loggerB= not UNIVERSAL::can($logger, "put")
| |||||||||||||||||||||||||||||
| 99 | 0 | warn "invalid logger: $logger (no put method), falling back to $basic_logger"; | |||||||||||||||||||||||||||
| 100 | 0 | undef $logger; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 10 | ▶ | unless ( defined $logger ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 10 | if ( !HAS_BASIC_LOGGER ) { | |||||||||||||||||||||||||||
| 105 | warn "$basic_logger is unavailable. Logging disabled!"; | ||||||||||||||||||||||||||||
| 106 | undef $logger; | ||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||
| 108 | $logger = "$basic_logger"->new( | ||||||||||||||||||||||||||||
| 109 | parent_alias => $opts{alias}, | ||||||||||||||||||||||||||||
| 110 | log_level => $opts{log_level}, | ||||||||||||||||||||||||||||
| 111 | 10 | ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | my $self = bless( { | ||||||||||||||||||||||||||||
| 116 | name => $opts{name}, | ||||||||||||||||||||||||||||
| 117 | opts => \%opts, | ||||||||||||||||||||||||||||
| 118 | heaps => {}, | ||||||||||||||||||||||||||||
| 119 | connections => 0, | ||||||||||||||||||||||||||||
| 120 | plugins => {}, | ||||||||||||||||||||||||||||
| 121 | plugin_pri => [], | ||||||||||||||||||||||||||||
| 122 | time_out_check => 10, # time_out checker | ||||||||||||||||||||||||||||
| 123 | type => delete $opts{_type}, | ||||||||||||||||||||||||||||
| 124 | 10 | ▶ | uuid => $uuid, | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 125 | is_forked => 0, | ||||||||||||||||||||||||||||
| 126 | _logger => $logger, | ||||||||||||||||||||||||||||
| 127 | }, ref $class || $class ); | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 10 | $self->{_uuid} = gen_uuid( $self ); | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 10 | ▶ | $self->check_params if ( $self->can( 'check_params' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 10 | ▶ | if ( $opts{max_connections} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | if ( HAS_BSD_RESOURCE ) { | |||||||||||||||||||||||||||
| 135 | my $ret = setrlimit( RLIMIT_NOFILE, $opts{max_connections}, $opts{max_connections} ); | ||||||||||||||||||||||||||||
| 136 | unless ( defined $ret && $ret ) { | ||||||||||||||||||||||||||||
| 137 | if ( $> == 0 ) { | ||||||||||||||||||||||||||||
| 138 | $self->_log(v => 1, msg => 'Unable to set max connections limit'); | ||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||
| 140 | $self->_log(v => 1, msg => 'Need to be root to increase max connections'); | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } else { | ||||||||||||||||||||||||||||
| 144 | 0 | $self->_log(v => 1, msg => 'Need BSD::Resource installed to increase max connections'); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 10 | $sprocket->add_component( $self ); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 10 | return $self; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 10 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: called CC=14 SCAR=36.1
| |||||||||||||||||||||||||||||
| 154 | 10 | my ( $self, $kernel, $session ) = @_[ OBJECT, KERNEL, SESSION ]; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 10 | $self->session_id( $session->ID ); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | $session->option( @{$self->{opts}->{session_options}} ) | |||||||||||||||||||||||||||
| 159 | 10 | ▶ | if ( $self->{opts}->{session_options} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | $kernel->alias_set( $self->{opts}->{alias} ) | ||||||||||||||||||||||||||||
| 162 | 10 | ▶ | if ( $self->{opts}->{alias} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 10 | ▶ | if ( $self->{opts}->{plugins} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 10 | foreach my $t ( @{ $self->opts->{plugins} } ) { | |||||||||||||||||||||||||||
| 167 | # convert CamelCase to camel_case | ||||||||||||||||||||||||||||
| 168 | 10 | $t = adjust_params($t); | |||||||||||||||||||||||||||
| 169 | $self->add_plugin( | ||||||||||||||||||||||||||||
| 170 | $t->{plugin}, | ||||||||||||||||||||||||||||
| 171 | 10 | ▶ | $t->{priority} || 0 | ||||||||||||||||||||||||||
|
Condition50%1/2
$t->{'priority'} || 0
MC/DC0%0/1
$t->{'priority'} || 0
$t->{'priority'}
Truth table50%1/2
A
A= $t->{'priority'}
| |||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 10 | ▶ | if ( my $ev = delete $self->opts->{event_manager} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | eval "use $ev->{module}"; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | $self->_log(v => 1, msg => "Error loading $ev->{module} : $@"); | |||||||||||||||||||||||||||
| 180 | 0 | $self->shutdown_all; | |||||||||||||||||||||||||||
| 181 | 0 | return; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | $ev->{options} = [] | ||||||||||||||||||||||||||||
| 184 | 0 | ▶ | unless ( $ev->{options} && ref( $ev->{options} ) eq 'ARRAY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ev->{"options"} and ref $ev->{"options"} eq "ARRAY"
MC/DC0%0/2
$ev->{"options"} and ref $ev->{"options"} eq "ARRAY"
$ev->{"options"}
ref $ev->{"options"} eq "ARRAY"
Truth table0%0/3
A and B
A= $ev->{"options"}B= ref $ev->{"options"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | $self->{event_manager} = "$ev->{module}"->new( | ||||||||||||||||||||||||||||
| 187 | 0 | @{$ev->{options}}, | |||||||||||||||||||||||||||
| 188 | parent_id => $self->session_id | ||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 10 | ▶ | $self->{aio} = defined( $sprocket_aio ) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | $self->{time_out_id} = $kernel->alarm_set( time_out_check => time() + $self->{time_out_check} ) | ||||||||||||||||||||||||||||
| 195 | 10 | ▶ | if ( $self->{time_out_check} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # TODO recheck and document | ||||||||||||||||||||||||||||
| 198 | $kernel->sig( DIE => 'exception' ) | ||||||||||||||||||||||||||||
| 199 | 10 | ▶ | if ( $self->{opts}->{use_exception_handler} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | $kernel->sig( TSTP => 'signals' ) | ||||||||||||||||||||||||||||
| 202 | 10 | ▶ | unless( $self->opts->{no_tstp} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 10 | $kernel->sig( INT => 'signals' ); | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 10 | $kernel->call( $session => '_startup' ); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 10 | return; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 3 | ▶ | sub _default { | ||||||||||||||||||||||||||
|
Subroutine
_default: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||
| 211 | 3 | my ( $self, $con, $cmd ) = @_[ OBJECT, HEAP, ARG0 ]; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 3 | ▶ | return if ( $cmd =~ m/^_(child|parent)/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 3 | ▶ | return $self->process_plugins( [ $cmd, $self, $con, @_[ ARG1 .. $#_ ] ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | if ( UNIVERSAL::can( $con, 'ID' ) ); | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | $self->_log(v => 1, msg => "_default called, no handler for event $cmd" | |||||||||||||||||||||||||||
| 219 | ." [$con] (the connection for this event may be gone)"); | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | return; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | sub signals { | ||||||||||||||||||||||||||
|
Subroutine
signals: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 225 | 0 | my ( $self, $signal_name ) = @_[ OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | $self->_log(v => 1, msg => "Client caught SIG$signal_name"); | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ( $signal_name eq 'INT' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 230 | # TODO do something here | ||||||||||||||||||||||||||||
| 231 | # to stop ctrl-c / INT | ||||||||||||||||||||||||||||
| 232 | #$_[KERNEL]->sig_handled(); | ||||||||||||||||||||||||||||
| 233 | } elsif ( $signal_name eq 'TSTP' ) { | ||||||||||||||||||||||||||||
| 234 | 0 | local $SIG{TSTP} = 'DEFAULT'; | |||||||||||||||||||||||||||
| 235 | 0 | kill( TSTP => $$ ); | |||||||||||||||||||||||||||
| 236 | 0 | $_[ KERNEL ]->sig_handled(); | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | return 0; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub sig_child { | ||||||||||||||||||||||||||
|
Subroutine
sig_child: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 243 | 0 | $_[KERNEL]->sig_handled(); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 8 | ▶ | sub new_connection { | ||||||||||||||||||||||||||
|
Subroutine
new_connection: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 247 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 8 | my $con = Sprocket::Connection->new( | |||||||||||||||||||||||||||
| 250 | parent_id => $self->session_id, | ||||||||||||||||||||||||||||
| 251 | @_ | ||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | # TODO ugh, move this stuff out of here | ||||||||||||||||||||||||||||
| 255 | $con->event_manager( $self->{event_manager}->{alias} ) | ||||||||||||||||||||||||||||
| 256 | 8 | ▶ | if ( $self->{event_manager} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 8 | $self->{heaps}->{ $con->ID } = $con; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 8 | my $len = $self->connections( scalar( keys %{$self->{heaps}} ) ); | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 8 | $sprocket->broadcast( 'sprocket.connection.create', { | |||||||||||||||||||||||||||
| 263 | source => $self, | ||||||||||||||||||||||||||||
| 264 | target => $con, | ||||||||||||||||||||||||||||
| 265 | } ); | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 8 | return $con; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # gets a connection obj from any component | ||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub get_connection { | ||||||||||||||||||||||||||
|
Subroutine
get_connection: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 272 | 0 | my ( $self, $id, $norec ) = @_; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ( my $con = $self->{heaps}->{ $id } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 0 | return $con; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 0 | ▶ | return undef if ( $norec ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | return $sprocket->get_connection( $id ); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 24 | ▶ | sub _log { | ||||||||||||||||||||||||||
|
Subroutine
_log: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 284 | 24 | ▶ | my ( $self, %o ) = ref $_[ KERNEL ] ? @_[ OBJECT, ARG0 .. $#_ ] : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 24 | ▶ | return unless defined $self->_logger; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 24 | $self->_logger->put( $self, \%o ); | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 8 | ▶ | sub cleanup { | ||||||||||||||||||||||||||
|
Subroutine
cleanup: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 290 | 8 | my ( $self, $con_id ) = @_[ OBJECT, ARG0 ]; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 8 | ▶ | if ( my $con = $self->{heaps}->{ $con_id } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 8 | ▶ | $self->process_plugins( [ $self->{type}.'_disconnected', $self, $con, 0 ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | unless ( defined $con->error ); | ||||||||||||||||||||||||||||
| 295 | 8 | $self->cleanup_connection( $con ); | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 15 | ▶ | sub cleanup_connection { | ||||||||||||||||||||||||||
|
Subroutine
cleanup_connection: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 300 | 15 | my ( $self, $con ) = @_; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 15 | ▶ | return unless( $con ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 15 | $sprocket->broadcast( 'sprocket.connection.destroy', { | |||||||||||||||||||||||||||
| 305 | source => $self, | ||||||||||||||||||||||||||||
| 306 | target => $con, | ||||||||||||||||||||||||||||
| 307 | } ); | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 15 | delete $self->{heaps}->{ $con->ID }; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 15 | $self->connections( scalar( keys %{$self->{heaps}} ) ); | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 15 | ▶ | $self->shutdown() | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->shutting_down and $self->connections <= 0
MC/DC50%1/2
$self->shutting_down and $self->connections <= 0
$self->shutting_down
$self->connections <= 0
Truth table66%2/3
A and B
A= $self->shutting_downB= $self->connections <= 0
| |||||||||||||||||||||||||||||
| 314 | if ( $self->shutting_down && $self->connections <= 0 ); | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 15 | return; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub shutdown_all { | ||||||||||||||||||||||||||
|
Subroutine
shutdown_all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 320 | 0 | shift; | |||||||||||||||||||||||||||
| 321 | 0 | $sprocket->shutdown_all( @_ ); | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 28 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 325 | 28 | ▶ | unless ( $_[KERNEL] && ref $_[KERNEL] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[2] and ref $_[2]
MC/DC50%1/2
$_[2] and ref $_[2]
$_[2]
ref $_[2]
Truth table66%2/3
A and B
A= $_[2]B= ref $_[2]
| |||||||||||||||||||||||||||||
| 326 | 14 | return $poe_kernel->call( shift->session_id => shutdown => @_ ); | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 14 | my ( $self, $kernel, $type ) = @_[ OBJECT, KERNEL, ARG0 ]; | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 14 | ▶ | if ( lc( $type ) eq 'soft' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 2 | $self->shutting_down( $type ); | |||||||||||||||||||||||||||
| 333 | 2 | $kernel->call( $_[SESSION] => 'begin_soft_shutdown' ); | |||||||||||||||||||||||||||
| 334 | 2 | return; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 12 | foreach ( values %{$self->{heaps}} ) { | |||||||||||||||||||||||||||
| 338 | 7 | $_->close( 1 ); # force | |||||||||||||||||||||||||||
| 339 | 7 | $self->cleanup_connection( $_ ); | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 12 | $self->{heaps} = {}; | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | # XXX proper? | ||||||||||||||||||||||||||||
| 344 | 12 | $kernel->sig( INT => undef ); | |||||||||||||||||||||||||||
| 345 | 12 | $kernel->sig( TSTP => undef ); | |||||||||||||||||||||||||||
| 346 | 12 | $kernel->alarm_remove_all(); | |||||||||||||||||||||||||||
| 347 | $kernel->alias_remove( $self->{opts}->{alias} ) | ||||||||||||||||||||||||||||
| 348 | 12 | ▶ | if ( $self->{opts}->{alias} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | # XXX remove plugins one by one? | ||||||||||||||||||||||||||||
| 351 | 12 | delete @{$self}{qw( wheel sf )}; | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | # if this is the last component, sprocket will shutdown aio | ||||||||||||||||||||||||||||
| 354 | 12 | $sprocket->remove_component( $self ); | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 12 | return; | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | sub begin_soft_shutdown { | ||||||||||||||||||||||||||
|
Subroutine
begin_soft_shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 360 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | $self->_log(v => 1, msg => $self->{name}." subclass didn't define a begin_soft_shutdown event. shutting down hard!"); | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 0 | $self->shutdown(); | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 0 | return; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub events_received { | ||||||||||||||||||||||||||
|
Subroutine
events_received: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 370 | 0 | my $self = $_[ OBJECT ]; | |||||||||||||||||||||||||||
| 371 | 0 | $self->process_plugins( [ 'events_received', $self, @_[ HEAP, ARG0 .. $#_ ] ] ); | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub events_ready { | ||||||||||||||||||||||||||
|
Subroutine
events_ready: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 375 | 0 | my $self = $_[ OBJECT ]; | |||||||||||||||||||||||||||
| 376 | 0 | $self->process_plugins( [ 'events_ready', $self, @_[ HEAP, ARG0 .. $#_ ] ] ); | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 0 | ▶ | sub exception { | ||||||||||||||||||||||||||
|
Subroutine
exception: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 380 | 0 | my ( $kernel, $self, $con, $sig, $error ) = @_[ KERNEL, OBJECT, HEAP, ARG0, ARG1 ]; | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | # TODO check exceptions with new POE | ||||||||||||||||||||||||||||
| 383 | $self->_log(v => 1, l => 1, msg => "plugin exception handled: ($sig) : " | ||||||||||||||||||||||||||||
| 384 | 0 | .join(' | ',map { $_.':'.$error->{$_} } keys %$error ) ); | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $con->close( 1 ) if ( UNIVERSAL::can( $con, 'close' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 0 | $kernel->sig_handled(); | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 0 | ▶ | sub time_out_check { | ||||||||||||||||||||||||||
|
Subroutine
time_out_check: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 391 | 0 | my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 0 | my $time = time(); | |||||||||||||||||||||||||||
| 394 | 0 | $self->{time_out_id} = $kernel->alarm_set( time_out_check => $time + $self->{time_out_check} ); | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 0 | foreach my $con ( values %{$self->{heaps}} ) { | |||||||||||||||||||||||||||
| 397 | 0 | ▶ | next unless ( $con ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if ( my $timeout = $con->time_out ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | 0 | ▶ | $self->process_plugins( [ $self->{type}.'_time_out', $self, $con, $time ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | if ( ( $con->active_time + $timeout ) < $time ); | ||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 10 | ▶ | sub add_plugin { | ||||||||||||||||||||||||||
|
Subroutine
add_plugin: called CC=7 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 406 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 10 | my $t = $self->{plugins}; | |||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 10 | my ( $plugin, $pri ) = @_; | |||||||||||||||||||||||||||
| 411 | 10 | my $uuid; | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 10 | ▶ | if ( $plugin->can( 'uuid' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 10 | $uuid = $plugin->uuid; | |||||||||||||||||||||||||||
| 415 | } else { | ||||||||||||||||||||||||||||
| 416 | 0 | warn "WARNING, plugin $plugin doesn't have a uuid," | |||||||||||||||||||||||||||
| 417 | ."contact the author and have them read the Sprocket::Plugin docs"; | ||||||||||||||||||||||||||||
| 418 | 0 | $uuid = "bad-plugin-$plugin"; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | warn "WARNING : Overwriting existing plugin '$uuid' (You have two plugins with the same id!!)" | ||||||||||||||||||||||||||||
| 422 | 10 | ▶ | if ( exists( $t->{ $uuid } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 10 | ▶ | $pri ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$pri ||= 0
MC/DC0%0/1
$pri ||= 0
$pri
Truth table50%1/2
A
A= $pri
| |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 10 | my $found = 0; | |||||||||||||||||||||||||||
| 427 | 10 | foreach ( values %$t ) { | |||||||||||||||||||||||||||
| 428 | 0 | ▶ | $found++ if ( $_->{priority} == $pri ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 10 | ▶ | warn "WARNING: You have defined more than one plugin with the same" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | ." priority, was this intended? plugin: $plugin uuid: $uuid pri: $pri" | ||||||||||||||||||||||||||||
| 433 | if ( $found ); | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 10 | $t->{ $uuid } = { | |||||||||||||||||||||||||||
| 436 | plugin => $plugin, | ||||||||||||||||||||||||||||
| 437 | priority => $pri, | ||||||||||||||||||||||||||||
| 438 | }; | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 10 | $plugin->parent_id( $self->session_id ); | |||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 10 | $sprocket->broadcast( 'sprocket.plugin.add', { | |||||||||||||||||||||||||||
| 443 | source => $self, | ||||||||||||||||||||||||||||
| 444 | target => $plugin, | ||||||||||||||||||||||||||||
| 445 | } ); | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 10 | $plugin->handle_event( plugin_start_aio => $self => $pri ); | |||||||||||||||||||||||||||
| 448 | 10 | $plugin->handle_event( add_plugin => $self => $pri ); | |||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | # recalc plugin order | ||||||||||||||||||||||||||||
| 451 | 10 | @{ $self->{plugin_pri} } = sort { | |||||||||||||||||||||||||||
| 452 | 10 | $t->{ $a }->{priority} <=> $t->{ $b }->{priority} | |||||||||||||||||||||||||||
| 453 | 0 | } keys %$t; | |||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 10 | return 1; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | sub remove_plugin { | ||||||||||||||||||||||||||
|
Subroutine
remove_plugin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 459 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 460 | 0 | my $uuid = shift; | |||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | # TODO remove by name or obj | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | my $t = $self->{plugins}; | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | my $plugin = delete $t->{ $uuid }; | |||||||||||||||||||||||||||
| 467 | 0 | ▶ | return 0 unless ( $plugin ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 0 | $sprocket->broadcast( 'sprocket.plugin.remove', { | |||||||||||||||||||||||||||
| 470 | source => $self, | ||||||||||||||||||||||||||||
| 471 | target => $plugin, | ||||||||||||||||||||||||||||
| 472 | } ); | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 0 | $plugin->{plugin}->handle_event( remove_plugin => $plugin->{priority} ); | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | # recalc plugin_pri | ||||||||||||||||||||||||||||
| 477 | 0 | @{ $self->{plugin_pri} } = sort { | |||||||||||||||||||||||||||
| 478 | 0 | $t->{ $a }->{priority} <=> $t->{ $b }->{priority} | |||||||||||||||||||||||||||
| 479 | 0 | } keys %$t; | |||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 0 | return 1; | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 41 | ▶ | sub process_plugins { | ||||||||||||||||||||||||||
|
Subroutine
process_plugins: called CC=10 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 485 | 41 | ▶ | my ( $self, $args, $i ) = $_[ KERNEL ] ? @_[ OBJECT, ARG0, ARG1 ] : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 41 | ▶ | return unless ( @{ $self->{plugin_pri} } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 41 | my $con = $args->[ CONNECTION ]; | |||||||||||||||||||||||||||
| 490 | 41 | ▶ | $con->state( $args->[ EVENT_NAME ] ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | if ( UNIVERSAL::can( $con, 'state' ) ); | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 41 | ▶ | if ( UNIVERSAL::can( $con, 'plugin' ) && ( my $t = $con->plugin ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
UNIVERSAL::can($con, "plugin") and my $t = $con->plugin
MC/DC100%2/2
UNIVERSAL::can($con, "plugin") and my $t = $con->plugin
UNIVERSAL::can($con, "plugin")
my $t = $con->plugin
Truth table100%3/3
A and B
A= UNIVERSAL::can($con, "plugin")B= my $t = $con->plugin
| |||||||||||||||||||||||||||||
| 494 | 24 | return $self->{plugins}->{ $t }->{plugin}->handle_event( @$args ); | |||||||||||||||||||||||||||
| 495 | } else { | ||||||||||||||||||||||||||||
| 496 | 17 | ▶ | $i ||= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$i ||= 0
MC/DC0%0/1
$i ||= 0
$i
Truth table50%1/2
A
A= $i
| |||||||||||||||||||||||||||||
| 497 | 17 | ▶ | if ( $#{ $self->{plugin_pri} } >= $i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | return if ( $self->{plugins}->{ | ||||||||||||||||||||||||||||
| 499 | $self->{plugin_pri}->[ $i ] | ||||||||||||||||||||||||||||
| 500 | 17 | ▶ | }->{plugin}->handle_event( @$args ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | 0 | $i++; | |||||||||||||||||||||||||||
| 503 | # avoid a post | ||||||||||||||||||||||||||||
| 504 | 0 | ▶ | return if ( $#{ $self->{plugin_pri} } < $i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | # XXX call? | ||||||||||||||||||||||||||||
| 508 | #$poe_kernel->call( $self->session_id => process_plugins => $args => $i ); | ||||||||||||||||||||||||||||
| 509 | 0 | $poe_kernel->yield( process_plugins => $args => $i ); | |||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 0 | ▶ | sub get_plugin { | ||||||||||||||||||||||||||
|
Subroutine
get_plugin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 513 | 0 | my ( $self, $uuid ) = @_; | |||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | return $self->{plugins}->{ $uuid }->{plugin} | ||||||||||||||||||||||||||||
| 516 | 0 | ▶ | if ( exists( $self->{plugins}->{ $uuid } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | # fall back to finding the plugin globally | ||||||||||||||||||||||||||||
| 519 | 0 | return $sprocket->get_plugin( $uuid ); | |||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 0 | ▶ | sub resolve_plugin_uuid { | ||||||||||||||||||||||||||
|
Subroutine
resolve_plugin_uuid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 523 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | 0 | my $plugin = grep { $name eq $_->{plugin}->name } values %{ $self->{plugins} }; | |||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | 0 | ▶ | return $plugin ? $plugin->uuid : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 0 | ▶ | sub forward_plugin_by_uuid { | ||||||||||||||||||||||||||
|
Subroutine
forward_plugin_by_uuid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 531 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 532 | 0 | my $uuid = shift; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 0 | ▶ | unless( exists ( $self->{plugins}->{ $uuid } ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | 0 | $self->_log( v => 4, msg => 'plugin not loaded! plugin uuid: '.$uuid ); | |||||||||||||||||||||||||||
| 536 | 0 | return 0; | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | # XXX | ||||||||||||||||||||||||||||
| 540 | 0 | my $con = $self->{heap}; | |||||||||||||||||||||||||||
| 541 | 0 | $con->plugin( $uuid ); | |||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 0 | return $self->process_plugins( [ $con->state, $self, $con, @_ ] ); | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 0 | ▶ | sub forward_plugin { | ||||||||||||||||||||||||||
|
Subroutine
forward_plugin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 547 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 548 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 0 | my ($plugin) = grep { $name eq $_->{plugin}->name } values %{ $self->{plugins} }; | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 0 | ▶ | unless( $plugin ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 553 | 0 | $self->_log( v => 4, msg => 'plugin not loaded! plugin: '.$name ); | |||||||||||||||||||||||||||
| 554 | 0 | return 0; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | # XXX | ||||||||||||||||||||||||||||
| 558 | 0 | my $con = $self->{heap}; | |||||||||||||||||||||||||||
| 559 | 0 | $con->plugin( $plugin->{plugin}->uuid ); | |||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 0 | return $self->process_plugins( [ $con->state, $self, $con, @_ ] ); | |||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | # helper used by Sprocket::Connection | ||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub call_in_ses_context { | ||||||||||||||||||||||||||
|
Subroutine
call_in_ses_context: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 566 | # must call in this in our session's context | ||||||||||||||||||||||||||||
| 567 | 0 | ▶ | unless ( $_[KERNEL] && ref $_[KERNEL] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[2] and ref $_[2]
MC/DC0%0/2
$_[2] and ref $_[2]
$_[2]
ref $_[2]
Truth table0%0/3
A and B
A= $_[2]B= ref $_[2]
| |||||||||||||||||||||||||||||
| 568 | 0 | return $poe_kernel->call( shift->session_id => @_ ); | |||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 0 | my $event = $_[ ARG0 ]; | |||||||||||||||||||||||||||
| 572 | 0 | return $_[ KERNEL ]->$event( @_[ ARG1 .. $#_ ] ); | |||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 5 | 1; | |||||||||||||||||||||||||||