NAME

POE::Kernel - an event driven application kernel in Perl


SYNOPSIS

  #!/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.


DESCRIPTION

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.

Private Methods

import

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.

_idle_queue_grow

Not documented. Please report a bug to the author.

_idle_queue_shrink

Not documented. Please report a bug to the author.

_idle_queue_size

Not documented. Please report a bug to the author.

_trap

Generate a trap message. Used to report internal POE errors.

_croak

Not documented. Please report a bug to the author.

_confess

Not documented. Please report a bug to the author.

_cluck

Not documented. Please report a bug to the author.

_carp

Not documented. Please report a bug to the author.

_warn

Not documented. Please report a bug to the author.

_die

Not documented. Please report a bug to the author.

_resolve_session

Not documented. Please report a bug to the author.

_test_if_kernel_is_idle

Not documented. Please report a bug to the author.

_explain_resolve_failure

Not documented. Please report a bug to the author.

_explain_return

Not documented. Please report a bug to the author.

_explain_usage

Not documented. Please report a bug to the author.

_dispatch_event

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.

_initialize_kernel_session

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.

DESTROY

Not documented. Please report a bug to the author.

_invoke_state

_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.

_internal_select

Not documented. Please report a bug to the author.

Public Methods

define_trace

Shorthand for defining a trace constant. Actually, perhaps it needs to go into the BEGIN block there.

find_loop

Adapt POE::Kernel's personality to whichever event loop is present.

load_loop

Not documented. Please report a bug to the author.

test_loop

Not documented. Please report a bug to the author.

sig

Register or remove signals.

Public interface for adding or removing signal handlers.

signal

Public interface for posting signal events.

sig_handled

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.

signal_ui_destroy

Attach a window or widget's destroy/closure to the UIDESTROY signal.

new

Not documented. Please report a bug to the author.

finalize_kernel

Do post-run cleanup.

run_one_timeslice

Not documented. Please report a bug to the author.

run

Not documented. Please report a bug to the author.

stop

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.

session_alloc

Dispatch _start to a session, allocating it in the kernel's data structures as a side effect.

detach_myself

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_child

Detach a child from this, the parent. The session being detached must be a child of the current session.

get_active_session

Not documented. Please report a bug to the author.

get_active_event

Not documented. Please report a bug to the author.

get_event_count

Not documented. Please report a bug to the author.

get_next_event_time

Not documented. Please report a bug to the author.

post

Post an event to the queue.

yield

Post an event to the queue for the current session.

call

Call an event handler directly.

queue_peek_alarms

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();

alarm

Not documented. Please report a bug to the author.

alarm_add

Add an alarm without clobbering previous alarms of the same name.

delay

Add a delay, which is just an alarm relative to the current time.

delay_add

Add a delay without clobbering previous delays of the same name.

alarm_set

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).

alarm_remove

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.

alarm_adjust

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.

delay_set

A convenient function for setting alarms relative to now. It also uses whichever time() POE::Kernel can find, which may be Time::HiRes'.

delay_adjust

Move a delay to a new offset from time(). As with alarm_adjust(), this is optimized internally for this sort of activity.

alarm_remove_all

Remove all alarms for the current session.

select

A higher-level select() that manipulates read, write and expedite selects together.

select_read

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.

select_write

Only manipulate the write select.

select_expedite

Only manipulate the expedite select.

select_pause_write

Turn off a handle's write mode bit without doing garbage-collection things.

select_resume_write

Turn on a handle's write mode bit without doing garbage-collection things.

select_pause_read

Turn off a handle's read mode bit without doing garbage-collection things.

select_resume_read

Turn on a handle's read mode bit without doing garbage-collection things.

alias_set

Not documented. Please report a bug to the author.

alias_remove

Not documented. Please report a bug to the author.

alias_resolve

Not documented. Please report a bug to the author.

alias_list

Not documented. Please report a bug to the author.

ID

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.

ID_id_to_session

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.

ID_session_to_id

Resolve a session reference to its corresponding ID.

refcount_increment

Not documented. Please report a bug to the author.

refcount_decrement

Not documented. Please report a bug to the author.

state

Add or remove event handlers from sessions.

Debugging and configuration constants.

Resolve $whatever into a session reference, trying every method we can until something succeeds.

Helpers.

Test whether POE has become idle.

Explain why a session could not be resolved.

Explain why a function is returning unsuccessfully.

Explain how the user made a mistake calling a function.

Signals

Let's talk about signals, shall we?

Helpful accessors. -><- Most of these are not documented.

Set an alias in the current session.

Remove an alias from the current session.

Resolve an alias into a session.

List the aliases for a given session.


EXAMPLES

This section accidentally left blank. Please report a bug to the author.


BUGS

This section accidentally left blank. Please report a bug to the author.


AUTHORS

This section accidentally left blank. Please report a bug to the author.


VERSION

$Id: Kernel.pm,v 1.333 2005/12/29 17:55:36 rcaputo Exp $


LICENSE

This section accidentally left blank. Please report a bug to the author.