POE
view release on metacpan or search on metacpan
lib/POE/Kernel.pm view on Meta::CPAN
my $session = $self->_resolve_session($dest_session);
unless (defined $session) {
$self->_explain_resolve_failure($dest_session);
return;
}
$self->_data_ev_enqueue(
$session, $kr_active_session,
EN_SIGNAL, ET_SIGNAL, [ $signal, @etc ],
(caller)[1,2], $kr_active_event
);
return 1;
}
# Public interface for flagging signals as handled. This will replace
# the handlers' return values as an implicit flag. Returns undef so
# it may be used as the last function in an event handler.
sub sig_handled {
my $self = $poe_kernel;
lib/POE/Kernel.pm view on Meta::CPAN
}
my $old_parent = $self->_data_ses_get_parent($kr_active_session->ID);
# Tell the old parent session that the child is departing.
# But not if the active event is ET_START, since that would generate
# a CHILD_LOSE without a CHILD_CREATE.
$self->_dispatch_event(
$old_parent, $self,
EN_CHILD, ET_CHILD, [ CHILD_LOSE, $kr_active_session, undef ],
(caller)[1,2], undef, monotime(), -__LINE__
)
unless $kr_active_event_type & ET_START;
# Tell the new parent (kernel) that it's gaining a child.
# (Actually it doesn't care, so we don't do that here, but this is
# where the code would go if it ever does in the future.)
# Tell the current session that its parentage is changing.
$self->_dispatch_event(
$kr_active_session, $self,
EN_PARENT, ET_PARENT, [ $old_parent, $self ],
(caller)[1,2], undef, monotime(), -__LINE__
);
$self->_data_ses_move_child($kr_active_session->ID, $self->ID);
# Success!
return 1;
}
# Detach a child from this, the parent. The session being detached
# must be a child of the current session.
lib/POE/Kernel.pm view on Meta::CPAN
$self->_data_ses_is_child($kr_active_session->ID, $child_session->ID)
) {
$! = EPERM;
return;
}
# Tell the current session that the child is departing.
$self->_dispatch_event(
$kr_active_session, $self,
EN_CHILD, ET_CHILD, [ CHILD_LOSE, $child_session, undef ],
(caller)[1,2], undef, monotime(), -__LINE__
);
# Tell the new parent (kernel) that it's gaining a child.
# (Actually it doesn't care, so we don't do that here, but this is
# where the code would go if it ever does in the future.)
# Tell the child session that its parentage is changing.
$self->_dispatch_event(
$child_session, $self,
EN_PARENT, ET_PARENT, [ $kr_active_session, $self ],
(caller)[1,2], undef, monotime(), -__LINE__
);
$self->_data_ses_move_child($child_session->ID, $self->ID);
# Success!
return 1;
}
### Helpful accessors.
lib/POE/Kernel.pm view on Meta::CPAN
unless (defined $session) {
$self->_explain_resolve_failure($dest_session);
return;
}
# Enqueue the event for "now", which simulates FIFO in our
# time-ordered queue.
$self->_data_ev_enqueue(
$session, $kr_active_session, $event_name, ET_POST, \@etc,
(caller)[1,2], $kr_active_event
);
return 1;
}
#------------------------------------------------------------------------------
# Post an event to the queue for the current session.
sub yield {
my ($self, $event_name, @etc) = ($poe_kernel, @_[1..$#_]);
lib/POE/Kernel.pm view on Meta::CPAN
_confess "<us> event name is undefined in yield()"
unless defined $event_name;
_carp(
"<us> The '$event_name' event is one of POE's own. Its " .
"effect cannot be achieved by yielding it"
) if exists $poes_own_events{$event_name};
};
$self->_data_ev_enqueue(
$kr_active_session, $kr_active_session, $event_name, ET_POST, \@etc,
(caller)[1,2], $kr_active_event
);
undef;
}
#------------------------------------------------------------------------------
# Call an event handler directly.
sub call {
my ($self, $dest_session, $event_name, @etc) = ($poe_kernel, @_[1..$#_]);
lib/POE/Kernel.pm view on Meta::CPAN
# should be made more clear in the documentation, so that people
# have a tendency not to abuse them. I discovered in xws that
# mixing the two types makes it harder than necessary to write
# deterministic programs, but the difficulty can be ameliorated if
# programmers set some base rules and stick to them.
if (wantarray) {
my @return_value = (
($session == $kr_active_session)
? $session->_invoke_state(
$session, $event_name, \@etc, (caller)[1,2],
$kr_active_event
)
: $self->_dispatch_event(
$session, $kr_active_session,
$event_name, ET_CALL, \@etc,
(caller)[1,2], $kr_active_event, monotime(), -__LINE__
)
);
$kr_exception and $self->_rethrow_kr_exception();
$! = 0;
return @return_value;
}
if (defined wantarray) {
my $return_value = (
$session == $kr_active_session
? $session->_invoke_state(
$session, $event_name, \@etc, (caller)[1,2],
$kr_active_event
)
: $self->_dispatch_event(
$session, $kr_active_session,
$event_name, ET_CALL, \@etc,
(caller)[1,2], $kr_active_event, monotime(), -__LINE__
)
);
$kr_exception and $self->_rethrow_kr_exception();
$! = 0;
return $return_value;
}
if ($session == $kr_active_session) {
$session->_invoke_state(
$session, $event_name, \@etc, (caller)[1,2],
$kr_active_event
);
}
else {
$self->_dispatch_event(
$session, $kr_active_session,
$event_name, ET_CALL, \@etc,
(caller)[1,2], $kr_active_event, monotime(), -__LINE__
);
}
$kr_exception and $self->_rethrow_kr_exception();
$! = 0;
return;
}
#==============================================================================
lib/POE/Kernel.pm view on Meta::CPAN
}
$self->_data_ev_clear_alarm_by_name($kr_active_session->ID(), $event_name);
# Add the new alarm if it includes a time. Calling _data_ev_enqueue
# directly is faster than calling alarm_set to enqueue it.
if (defined $time) {
$self->_data_ev_enqueue
( $kr_active_session, $kr_active_session,
$event_name, ET_ALARM, [ @etc ],
(caller)[1,2], $kr_active_event, $time,
);
}
else {
# The event queue has become empty? Stop the time watcher.
$self->loop_pause_time_watcher() unless $kr_queue->get_item_count();
}
return 0;
}
lib/POE/Kernel.pm view on Meta::CPAN
};
unless (defined $event_name and defined $time) {
$self->_explain_return("invalid parameter to alarm_add() call");
return EINVAL;
}
$self->_data_ev_enqueue
( $kr_active_session, $kr_active_session,
$event_name, ET_ALARM, [ @etc ],
(caller)[1,2], $kr_active_event, $time,
);
return 0;
}
# Add a delay, which is like an alarm relative to the current time.
sub delay {
my ($self, $event_name, $delay, @etc) = ($poe_kernel, @_[1..$#_]);
my $pri = monotime();
lib/POE/Kernel.pm view on Meta::CPAN
}
if (defined $delay) {
$self->_data_ev_clear_alarm_by_name($kr_active_session->ID(), $event_name);
# Add the new alarm if it includes a time. Calling _data_ev_enqueue
# directly is faster than calling alarm_set to enqueue it.
$self->_data_ev_enqueue
( $kr_active_session, $kr_active_session,
$event_name, ET_ALARM, [ @etc ],
(caller)[1,2], $kr_active_event, undef, $delay, $pri+$delay
);
}
else {
$self->alarm($event_name);
}
return 0;
}
# Add a delay without clobbering previous delays of the same name.
lib/POE/Kernel.pm view on Meta::CPAN
};
unless (defined $event_name and defined $delay) {
$self->_explain_return("invalid parameter to delay_add() call");
return EINVAL;
}
$self->_data_ev_enqueue
( $kr_active_session, $kr_active_session,
$event_name, ET_ALARM, [ @etc ],
(caller)[1,2], $kr_active_event, undef, $delay, $pri+$delay
);
return 0;
}
#------------------------------------------------------------------------------
# New style alarms.
# Set an alarm. This does more *and* less than plain alarm(). It
# only sets alarms (that's the less part), but it also returns an
lib/POE/Kernel.pm view on Meta::CPAN
if (ASSERT_USAGE) {
_carp(
"<us> The '$event_name' event is one of POE's own. Its " .
"effect cannot be achieved by setting an alarm for it"
) if exists $poes_own_events{$event_name};
}
return $self->_data_ev_enqueue
( $kr_active_session, $kr_active_session, $event_name, ET_ALARM, [ @etc ],
(caller)[1,2], $kr_active_event, $time,
);
}
# Remove an alarm by its ID. TODO Now that alarms and events have
# been recombined, this will remove an event by its ID. However,
# nothing returns an event ID, so nobody knows what to remove.
sub alarm_remove {
my ($self, $alarm_id) = ($poe_kernel, @_[1..$#_]);
lib/POE/Kernel.pm view on Meta::CPAN
}
unless (defined $seconds) {
$self->_explain_usage("undefined seconds in delay_set()");
$! = EINVAL;
return;
}
return $self->_data_ev_enqueue
( $kr_active_session, $kr_active_session, $event_name, ET_ALARM, [ @etc ],
(caller)[1,2], $kr_active_event, $t, $seconds, $pri+$seconds
);
}
# Move a delay to a new offset from time(). As with alarm_adjust(),
# this is optimized internally for this sort of activity.
sub delay_adjust {
# Always always always grab time() ASAP, so that the eventual
# time we set the delay for is as close as possible to the time
# at which they ASKED for the delay, not when we actually set it.
( run in 1.123 second using v1.01-cache-2.11-cpan-a3c8064c92c )