
POE::Component::AI::MegaHAL - A non-blocking wrapper around AI::MegaHAL.

use POE qw(Component::AI::MegaHAL);
my $poco = POE::Component::AI::MegaHAL->spawn( autosave => 1, debug => 0,
path => '.', options => { trace => 0 } );
POE::Session->create(
package_states => [
'main' => [ qw(_start _got_reply) ],
],
);
$poe_kernel->run();
exit 0;
sub _start {
$_[KERNEL]->post( $poco->session_id() => do_reply => { text => 'What is a MegaHAL ?', event => '_got_reply' } );
undef;
}
sub _got_reply {
print STDOUT $_[ARG0]->{reply} . "\n";
$_[KERNEL]->post( $poco->session_id() => 'shutdown' );
undef;
}

POE::Component::AI::MegaHAL provides a non-blocking wrapper around AI::MegaHAL.

spawnAccepts a number of arguments:
'autosave' and 'path' are passed to AI::MegaHAL; 'debug' sets the debug mode; 'options' is a hashref of parameters to pass to the component's POE::Session; 'alias', is supported for using POE::Kernel aliases;
session_idReturns the component session id.

These are the events that we'll accept.
All megahal related events accept a hashref as the first parameter. You must specify 'event' as the event in your session where you want the response to go. See the example in the SYNOPSIS.
The 'shutdown' event doesn't require any parameters.
intial_greetingSolicits the initial greeting returned by the brain on start-up.
do_replySubmits text to the brain and solicits a reply. In the hashref you must specify 'text' with the data you wish to submit to the AI::MegaHAL object.
learnSubmits text to the brain without soliciting a reply. In the hashref you must specify 'text' with the data you wish to submit to the AI::MegaHAL object.
_cleanupSaves the megahal brain to file.
shutdownShuts the component down gracefully. Any pending requests will be serviced and return events dispatched.

Events generated by the component in response to the above input will have a hashref as ARG0. $hashref->{reply} will contain the applicable response from the brain.

Chris 'BinGOs' Williams
with contributions by David Davies <xantus>.

Copyright © Chris Williams and David Davis
This module may be used, modified, and distributed under the same terms as Perl itself. Please see the license that came with your Perl distribution for details.
