Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/RDB/AsyncSearch.pm view on Meta::CPAN
my ($dbpath, $tag, @results) = @$input;
my $request = delete $heap->{Requests}->{$tag};
unless ($request) {
carp "severe oddness: results from a request tag we don't know";
return
}
my $sender_id = $request->{SenderID};
my $hints = $request->{Hints};
## Returns: resultset as arrayref, original hints hash
## (passed in via search)
my $event = $heap->{ResultEvent};
$kernel->post( $sender_id, $event, \@results, $hints );
}
sub worker_sigchld {
my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
my $pid = $_[ARG1];
my $wheel = delete $heap->{Wheels}->{PID}->{$pid};
my $wid = $wheel->ID;
delete $heap->{RequestsByWID}->{$wid};
$kernel->yield( 'push_pending' );
}
sub worker_stderr {
my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
my ($input, $wid) = @_[ARG0, ARG1];
my $request_id = $heap->{RequestsByWID}->{$wid};
my $request = delete $heap->{Requests}->{$request_id};
if ($request) {
my $sender_id = $request->{SenderID};
my $hints = $request->{Hints};
my $event = $heap->{ErrorEvent};
$kernel->post( $sender_id, $event, $input, $hints );
} else {
carp "stderr from non-avail request: $input"
}
## These should sigchld and go away.
}
1;
__END__
=pod
=head1 NAME
Bot::Cobalt::Plugin::RDB::AsyncSearch - Asynchronous RDB deep search
=head1 SYNOPSIS
## Inside a POE::Session
my $async_sessID = Bot::Cobalt::Plugin::RDB::AsyncSearch->spawn(
MaxWorkers => 5,
ResultEvent => 'got_rdb_result',
ErrorEvent => 'got_rdb_error',
);
$poe_kernel->post( $async_sessID,
'search_rdb',
$rdb_path,
$regex,
$hints_hash
);
=head1 DESCRIPTION
This is a simple POE session for managing fork()/exec()'d
Bot::Cobalt::Plugin::RDB::AsyncSearch::Worker instances via
L<POE::Wheel::Run>.
It does not interact with the L<Bot::Cobalt> core directly in any way;
it can be used from any POE session to deep-search RDBs.
Searches should be posted to the B<search_rdb> event (see L</SYNOPSIS>).
Results are returned to the specified B<ResultEvent>; the first argument
is an array reference of results, the second argument is the $hints_hash
originally passed in via B<search_rdb>.
=head1 AUTHOR
Jon Portnoy <avenj@cobaltirc.org>
L<http://www.cobaltirc.org>
=cut
( run in 0.955 second using v1.01-cache-2.11-cpan-39bf76dae61 )