NAME¶
POE::Component::DBIAgent::Helper - DBI Query Helper for DBIAgent
SYNOPSYS¶
use Socket qw/:crlf/;
use POE qw/Filter::Line Wheel::Run Component::DBIAgent::Helper/;
sub _start {
my $helper = POE::Wheel::Run ->new(
Program => sub {
POE::Component::DBIAgent::Helper->run($self->{dsn},
$self->{queries}
);
},
StdoutEvent => 'db_reply',
StderrEvent => 'remote_stderr',
ErrorEvent => 'error',
StdinFilter => POE::Filter::Line->new(),
StdoutFilter => POE::Filter::Line->new( Literal => CRLF),
StderrFilter => POE::Filter::Line->new(),
)
or carp "Can't create new DBIAgent::Helper: $!\n";
}
sub query {
my ($self, $query, $package, $state, @rest) = @_;
$self->{helper}->put(join '|', $query, $package, $state, @rest);
}
sub db_reply {
my ($kernel, $self, $heap, $input) = @_[KERNEL, OBJECT, HEAP, ARG0];
# $input is either the string 'EOF' or a Storable object.
}
DESCRIPTION¶
This is our helper routine for DBIAgent. It accepts queries on STDIN, and
returns the results on STDOUT. Queries are returned on a row-by-row basis,
followed by a row consisting of the string 'EOF'.
Each row is the return value of $sth->fetch, which is an arrayref. This row
is then passed to Storable for transport, and printed to STDOUT. HOWEVER,
Storable uses newlines ("\n") in its serialized strings, so the
Helper is designed to use the "network newline" pair CR LF as the
line terminator for STDOUT.
When
fetch() returns undef, one final row is returned to the calling
state: the string 'EOF'. Sessions should test for this value FIRST when being
invoked with input from a query.
Initialization¶
The Helper has one public subroutine, called "run()", and is invoked
with two parameters:
- The DSN
- An arrayref of parameters to pass to DBI->connect
(usually a dsn, username, and password).
- The Queries.
- A hashref of the form Query_Name => "$SQL".
See POE::Component::DBIAgent for details.
BUGS¶
I have NO idea what to do about handling signals intelligently. Specifically,
under some circumstances, Oracle will refuse to acknowledge SIGTERM
(presumably since its libraries are non-reentrant) so sometimes SIGKILL is
required to terminate a Helper process.
AUTHOR¶
This module has been fine-tuned and packaged by Rob Bloodgood
<robb@empire2.com>. However, most of the code came directly from Fletch
<fletch@phydeaux.org>, either directly (Po:Co:DBIAgent:Queue) or via his
ideas. Thank you, Fletch!
However, I own all of the bugs.
This module is free software; you may redistribute it and/or modify it under the
same terms as Perl itself.