POE::Kernel - an event driven application kernel in Perl
#!/usr/bin/perl
use warnings; use strict;
use POE;
POE::Session->create(
inline_states => {
_start => \&start_session,
tick => \&handle_tick,
count => \&handle_count,
},
);
POE::Kernel->run(); exit;
sub start_session {
my ($kernel, $heap) = @_[KERNEL, HEAP];
$heap->{count} = 0;
$kernel->yield( "count" );
$kernel->delay( tick => 1 );
}
sub handle_count {
$_[HEAP]{count}++;
$kernel->yield( "count" );
}
sub handle_tick {
print "Tick! Count = $_[HEAP]{count}\n";
$kernel->delay( tick => 1 );
}
Other POE::Kernel facilities include file I/O events, signal events, and other types of timer events.
POE::Kernel is an event driven application kernel. It drives one or more POE::Session instances, each of which is a lightweight, cooperatively multitasked session within a POE process.
import() exports POE::Kernel constants into the user's package.
It accepts an optional hash of named parameters, only one of which
is currently supported: loop.
The loop parameter explicitly specifies which POE::Loop class will be used. It's generally not necessary since POE can automatically detect which loop is in effect at the time POE::Kernel is loaded.
In rare instances, one event loop may use another. Gtk2 uses Glib, for instance. It becomes necessary to specify which POE::Loop library you really need in these cases.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Generate a trap message. Used to report internal POE errors.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Send an event to a session right now. Used by _disp_select to
expedite select() events, and used by run() to deliver posted events
from the queue.
Dispatch an event to its session. A lot of work goes on here.
POE's main loop! Now with Tk and Event support!
Do pre-run startup. Initialize the event loop, and allocate a session structure to represent the Kernel.
Not documented. Please report a bug to the author.
_invoke_state is what _dispatch_event calls to dispatch a transition event. This is the kernel's _invoke_state so it can receive events. These are mostly signals, which are propagated down in _dispatch_event.
Not documented. Please report a bug to the author.
Shorthand for defining a trace constant. Actually, perhaps it needs to go into the BEGIN block there.
Adapt POE::Kernel's personality to whichever event loop is present.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Register or remove signals.
Public interface for adding or removing signal handlers.
Public interface for posting signal events.
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.
Attach a window or widget's destroy/closure to the UIDESTROY signal.
Not documented. Please report a bug to the author.
Do post-run cleanup.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Stops the kernel cold. XXX Experimental!
No events happen as a result of this, all structures are cleaned up
except the kernel's. Even the current session is cleaned up, which
may introduce inconsistencies in the current session... as
_dispatch_event() attempts to clean up for a defunct session.
Dispatch _start to a session, allocating it in the kernel's data structures as a side effect.
Detach a session from its parent. This breaks the parent/child relationship between the current session and its parent. Basically, the current session is given to the Kernel session. Unlike with _stop, the current session's children follow their parent.
TODO - Calling detach_myself() from _start means the parent receives
a ``_child lose'' event without ever seeing ``_child create''.
Detach a child from this, the parent. The session being detached must be a child of the current session.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Post an event to the queue.
Post an event to the queue for the current session.
Call an event handler directly.
Peek at pending alarms. Returns a list of pending alarms. This function is deprecated; its lack of documentation is by design. Here's the old POD, in case you're interested.
# Return the names of pending timed events. @event_names = $kernel->queue_peek_alarms( );
queue_peek_alarms
queue_peek_alarms() returns a time-ordered list of event names from
the current session that have pending timed events. If a event
handler has more than one pending timed event, it will be listed
that many times.
my @pending_timed_events = $kernel->queue_peek_alarms();
Not documented. Please report a bug to the author.
Add an alarm without clobbering previous alarms of the same name.
Add a delay, which is just an alarm relative to the current time.
Add a delay without clobbering previous delays of the same name.
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 alarm ID (that's the more part).
Remove an alarm by its ID. -><- 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.
Move an alarm to a new time. This virtually removes the alarm and
re-adds it somewhere else. In reality, adjust_priority() is
optimized for this sort of thing.
A convenient function for setting alarms relative to now. It also
uses whichever time() POE::Kernel can find, which may be
Time::HiRes'.
Move a delay to a new offset from time(). As with alarm_adjust(), this is optimized internally for this sort of activity.
Remove all alarms for the current session.
A higher-level select() that manipulates read, write and expedite
selects together.
select_read() enables or disables an I/O watcher, specifically one
that generates events when a FILEHANDLE is ready to be read. Other
watchers for the same FILEHANDLE are not affected.
A FILEHANDLE may only generate one EVENT_NAME in a particular mode. Setting a second EVENT_NAME effectively overwrites the first.
A FILEHANDLE may only be watched in a particular mode (read, write, or expedite) by a single session. This limitation is in place to avoid contention that might occur if two or more sessions tried to access a file at once.
@param FILEHANDLE The filehandle to be watched or ignored. @param EVENT_NAME (optional) When defined, the event to generate when the FILEHANDLE becomes ready for reading. Omitting this parameter signifies that POE::Kernel should stop watching the FILEHANDLE. @param ARGUMENT_LIST (optional) Optional data that will be passed to event handlers with every event. The first of these will be passed in ARG2, the second in ARG3, and so on.
@event ARG0 The filehandle that is ready for reading. This is the FILEHANDLE that was used to call select_read(). @event ARG1 The number 1, which signifies that FILEHANDLE is ready for reading. @event ARG2.. Event fields ARG2 and later contain a copy of the ARGUMENT_LIST included in the call to select_read().
@return Always returns 0.
Only manipulate the write select.
Only manipulate the expedite select.
Turn off a handle's write mode bit without doing garbage-collection things.
Turn on a handle's write mode bit without doing garbage-collection things.
Turn off a handle's read mode bit without doing garbage-collection things.
Turn on a handle's read mode bit without doing garbage-collection things.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Return the Kernel's ``unique'' ID. There's only so much uniqueness available; machines on separate private 10/8 networks may have identical kernel IDs. The chances of a collision are vanishingly small.
The Kernel and Session IDs are based on Philip Gwyn's code. I hope he still can recognize it.
Resolve an ID to a session reference. This function is virtually moot now that _resolve_session does it too. This explicit call will be faster, though, so it's kept for things that can benefit from it.
Resolve a session reference to its corresponding ID.
Not documented. Please report a bug to the author.
Not documented. Please report a bug to the author.
Add or remove event handlers from sessions.
Helpers.
Let's talk about signals, shall we?
This section accidentally left blank. Please report a bug to the author.
This section accidentally left blank. Please report a bug to the author.
This section accidentally left blank. Please report a bug to the author.
$Id: Kernel.pm,v 1.333 2005/12/29 17:55:36 rcaputo Exp $
This section accidentally left blank. Please report a bug to the author.