Amethyst
view release on metacpan or search on metacpan
Amethyst.pm view on Meta::CPAN
# This no longer creates a POE::Session
sub handler_add_brain {
my ($kernel, $session, $heap, $package, $args)
= @_[KERNEL, SESSION, HEAP, ARG0, ARG1];
my $name = $args->{Name} || $package;
my $priority = $args->{Priority} || 1;
eval qq{ require $package; };
if ($@) {
print STDERR "Amethyst: Failed to add brain $name ($package)\n";
$heap->{BrainsFailed}->{$name} = 1;
}
else {
my $brain = $package->new($args);
$heap->{Brains}->{$name} = [ $brain, $name, $priority, ];
$brain->init();
}
}
sub handler_connect {
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
print STDERR "Amethyst: connecting\n";
unless (%{ $heap->{Brains} }) {
print STDERR "Amethyst: Warning: No brains!\n";
}
foreach (values %{$heap->{Connections}}) {
print STDERR "Amethyst: Connecting $_\n";
$kernel->post($_, 'connect');
}
}
sub handler_think {
my ($kernel, $session, $heap, $message, $brains, @args) =
@_[KERNEL, SESSION, HEAP, ARG0 .. $#_];
my @brains = $brains ? @$brains : keys %{$heap->{Brains}};
foreach my $name (@brains) {
if ($heap->{BrainsFailed}->{$name}) {
print STDERR "Amethyst: Cannot think in brain $name: " .
"it failed to load at startup\n";
next;
}
my $brain = $heap->{Brains}->{$name};
if ($heap->{BrainsFailed}->{$name}) {
print STDERR "Amethyst: Cannot think in brain $name: " .
"no such brain!\n";
next;
}
last if $brain->[0]->think($message, @args);
}
}
1;
__END__
# Below is stub documentation for your module. You better edit it!
=head1 NAME
Amethyst - Perl extension for blah blah blah
=head1 SYNOPSIS
use POE;
use Amethyst;
new Amethyst;
$poe_kernel->post('amethyst', 'add_brain',
'Amethyst::Brain::Infobot', \%infobot_params);
$poe_kernel->post('amethyst', 'add_brain',
'Amethyst::Brain::Eliza', \%eliza_params);
$poe_kernel->post('amethyst', 'add_connection',
'Amethyst::Connection::IRC', \%irc_params);
$poe_kernel->post('amethyst', 'connect');
$poe_kernel->run;
=head1 DESCRIPTION
Amethyst is a bot core capable of handling parsing and routing
of messages between connections and brains. Amethyst can handle
an arbitrary number of connections of arbitrary types (given an
appropriate module in Amethyst::Connection::*), routing these messages
fairly arbitrarily through multiple processing cores (brains, live
in Amethyst::Brain::*), and responding to these messages on other
arbitrary connections.
The included script example.pl gives an example of the usage of
the script.
=head2 EXPORT
Nothing.
=head1 AUTHOR
Shevek, E<lt>cpan@anarres.orgE<gt>
=head1 SEE ALSO
L<perl>, L<POE>.
=cut
( run in 1.236 second using v1.01-cache-2.11-cpan-524268b4103 )