|  |  
 |   |   
 NAMEPOE::Component::LaDBI - POE Component that spawns a perl subprocess to handle non-blocking access to the DBI API. SYNOPSIS use POE::Component::LaDBI;
 POE::Component::LaDBI->create( Alias => "ladbi" );
 $k->call(ladbi => "register",
          OfflineEvent => 'db_offline');
 $k->post(ladbi => "connect",
          SuccessEvent => "connected",
          FailureEvent  => "connect_failed",
          Args => ["dbi:Pg:dbname=$dbname", $user, $passwd],
          UserData => $stuff );
 $k->post(ladbi => "disconnect",
          SuccessEvent => "disconnected",
          FailureEvent  => "disconnect_failed",
          HandleId => $dbh_id,
          UserData => $stuff);
 $k->post("ladbi" => "prepare",
          SuccessEvent => "prepared",
          FailureEvent => "prepare_failed",
          HandleId => $dbh_id,
          Args => [$sql], 
          UserData => $stuff);
 $k->post("ladbi" => "finish",
          SuccessEvent => "finished",
          FailureEvent => "finish_failed",
          HandleId => $sth_id,
          UserData => $stuff);
 $k->post("ladbi" => "execute",
          SuccessEvent => "executed",
          FailureEvent => "execute_failed",
          HandleId => $sth_id,
          Args => [$bind_val0, $bind_val1, ...],
          UserData => $stuff);
 $k->post("ladbi" => "rows",
          SuccessEvent => "rows_found",
          FailureEvent => "rows_failed",
          HandleId => $sth_id,
          UserData => $stuff);
 $k->post("ladbi" => "fetchrow",
          SuccessEvent => "row_fetched",
          FailureEvent => "fetch_failed",
          HandleId => $sth_id,
          UserData => $stuff);
 $k->post("ladbi" => "fetchrow_hash",
          SuccessEvent => "row_fetched",
          FailureEvent => "fetch_failed",
          HandleId => $sth_id,
          UserData => $stuff);
 $k->post("ladbi" => "fetchall",
          SuccessEvent => "all_fetched",
          FailureEvent => "fetchall_failed",
          HandleId => $sth_id,
          Args => [ @optional_indicies ],
          UserData => $stuff);
 $k->post("ladbi" => "fetchall_hash",
          SuccessEvent => "all_fetched",
          FailureEvent => "fetchall_failed",
          HandleId => $sth_id,
          Args => [ @optional_keys ],
          UserData => $stuff);
 $k->post("ladbi" => "ping",
         SuccessEvent => "check_ping_results",
         FailureEvent => "ping_failed",
         HandleId => $dbh_id,
         UserData => $stuff);
 $k->post("ladbi" => "do",
          SuccessEvent => "check_do_results",
          FailureEvent => "do_failed",
          HandleId => $dbh_id,
          Args => [ $sql, $attr_hashref, @bind_values ],
          UserData => $stuff);
 $k->post("ladbi" => "begin_work",
          SuccessEvent => "check_transactions_enabled",
          FailureEvent => "begin_work_failed",
          HandleId => $dbh_id,
          UserData => $stuff);
 $k->post("ladbi" => "commit",
          SuccessEvent => "check_commit",
          FailureEvent => "commit_failed",
          HandleId => $dbh_id,
          UserData => $stuff);
 $k->post("ladbi" => "rollback",
          SuccessEvent => "check_rollback",
          FailureEvent => "rollback_failed",
          HandleId => $dbh_id,
          UserData => $stuff);
 $k->post("ladbi" => "selectall",
          SuccessEvent => "check_results",
          FailureEvent => "selectall_failed",
          HandleId => $dbh_id,
          Args => [ $sql ],
          UserData => $stuff);
 $k->post("ladbi" => "selectall_hash",
          SuccessEvent => "check_results",
          FailureEvent => "selectall_failed",
          HandleId => $dbh_id,
          Args => [ $sql, $key_field ],
          UserData => $stuff);
 $k->post("ladbi" => "selectcol",
          SuccessEvent => "check_results",
          FailureEvent => "selectcol_failed",
          HandleId => $dbh_id,
          Args => [ $sql, $attr_hashref ],
          UserData => $stuff);
 $k->post("ladbi" => "selectrow",
          SuccessEvent => "check_results",
          FailureEvent => "selectrow_failed",
          HandleId => $dbh_id,
          Args => [ $sql, $attr_hashref ],
          UserData => $stuff);
 $k->post("ladbi" => "quote",
          SuccessEvent => "use_quote_results",
          FailureEvent => "quote_failed",
          HandleId => $dbh_id,
          Args => [ $value ],
          UserData => $stuff);
DESCRIPTIONLaDBI Session Events
 
 LaDBI Request EventsAll request events have the same handler. This is because the handler merely creates a request message and sends it to the perl sub-process which is doing the actuall DBI calls. The handler takes the same arguments. Not all events use the all the argument fields. The arguments fields/keys are: 
 
 
 
 
 EXAMPLE  use strict;
  use warnings;
  use POE;
  use POE::Component::LaDBI;
  my $LADBI_ALIAS = "ladbi";
  my $DSN = "dbi:Pg:dbname=test";
  my $USER = "dbuser";
  my $PASSWD = "secret";
  my $SQL = "SELECT * FROM contacts";
  POE::Component::LaDBI->create(Alias => $LADBI_ALIAS)
    or die "Failed to create a POE::Component::LaDBI session\n";
  POE::Session->create
    (args => [$DSN, $USER, $PASSWD, $SQL],
     inline_states =>
      {
       _start          => sub {
         my ($dsn, $user, $passwd, $sql) = @_[ARG0..ARG3];
         print STDERR "_start: args=($dsn,$user,$passwd)\n";
         $_[HEAP]->{sql} = $sql;
         $_[KERNEL]->post($LADBI_ALIAS => "connect",
                          SuccessEvent => "selectall",
                          FailureEvent => "dberror",
                          Args => [ $dsn, $user, $passwd ]);
       },
       _stop           => sub {
         print STDERR "_stop: client session ended.\n";
       },
       shutdown        => sub {
         print STDERR "shutdown: sending shutdown to $LADBI_ALIAS\n";
         $_[KERNEL]->post($LADBI_ALIAS => "shutdown");
       },
       selectall       => sub {
         my ($dbh_id, $datatype, $data) = @_[ARG0..ARG2];
         $_[HEAP]->{dbh_id} = $dbh_id;
         print STDERR "selectall: dbh_id=$dbh_id\n";
         $_[KERNEL]->post($LADBI_ALIAS => "selectall",
                          SuccessEvent => "display_results",
                          FailureEvent => "dberror",
                          HandleId     => $dbh_id,
                          Args         => [ $_[HEAP]->{sql} ] );
       },
       display_results => sub {
         my ($dbh_id, $datatype, $data) = @_[ARG0..ARG2];
         print STDERR "display_results: dbh_id=$dbh_id\n";
         for my $row ( @$data ) {
           print join(",", @$row), "\n";
         }
         $_[KERNEL]->post($LADBI_ALIAS => "disconnect",
                          SuccessEvent => "shutdown",
                          FailureEvent => "dberror",
                          HandleId     => $dbh_id);
       },
       dberror         => sub {
         my ($dbh_id, $errtype, $errstr, $err) = @_[ARG0..ARG3];
         print STDERR "dberror: dbh_id  = $dbh_id\n";
         print STDERR "dberror: errtype = $errtype\n";
         print STDERR "dberror: errstr  = $errstr\n";
         print STDERR "dberror: err     = $err\n" if $errtype eq "ERROR";
         $_[KERNEL]->yield("shutdown");
       }
      } #end: inline_states
    ) #end: POE::Session->create()
  or die "Failed to instantiate POE::Session\n";
  $poe_kernel->run();
  exit 0;
  __END__
DEBUGGINGIf the environment variable LADBI_DEBUG is set to a true value (perl-wise), or the ":DEBUG" symbol is in the use statement import list (eg "use POE::Component::LaDBI qw(:DEBUG)"), then debugging will be turned on. When debuggind is turned on, POE::Component::LaDBI->run() will open and log messages to a file whos name is indicated in $POE::Component::LaDBI::DEBUG_FILE. The debug log is set to "ladbi_run.log" by default. EXPORTNone by default. AUTHORSean M. Egan, <seanegan:bigfoot_com> SEE ALSOperl, POE, DBI, POE::Component::LaDBI::Engine, POE::Component::LaDBI::Request, POE::Component::LaDBI::Response 
 
 |