POE::Component::AI::MegaHAL - A non-blocking wrapper around AI::MegaHAL.
version 1.20
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.
spawn
Accepts 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_id
Returns 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_greeting
Solicits the initial greeting returned by the brain on start-up.
do_reply
Submits 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.
learn
Submits 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.
_cleanup
Saves the megahal brain to file.
shutdown
Shuts 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.
AI::MegaHAL
http://megahal.sourceforge.net/
POE
Chris Williams <chris@bingosnet.co.uk>
David Davis <xantus@cpan.org>
This software is copyright (c) 2017 by Chris Williams.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install POE::Component::AI::MegaHAL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::AI::MegaHAL
CPAN shell
perl -MCPAN -e shell install POE::Component::AI::MegaHAL
For more information on module installation, please visit the detailed CPAN module installation guide.