POE::Component::DBIAgent::Helper3pm
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.}
Overview
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.
Releases
8 releases since Debian 6.0 (Squeeze); the text changed 2 times.