processing unsuccessful db connections

rahed <[email protected]> Tue, 27 Apr 2010 12:18:42 +0200
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
Hi,

I am starting with POE and want to query a few databases (among other
things). I chose PoCo::SimpleDBI but am not able to end the session if
the connection doesn't succeed. The event dispatcher runs indefinitely.
What is missing in my code?


use strict;
use warnings;
use POE;
use POE::Component::SimpleDBI;

POE::Component::SimpleDBI->new('SimpleDBI') or die 'Unable to create the DBI session';

POE::Session->create(
  inline_states => {
    _start  => sub {
      $_[KERNEL]->post('SimpleDBI','CONNECT',
		       DSN      => 'myconnectionstring',
		       USERNAME => 'myuser',
		       PASSWORD => 'mypasswd',
		       EVENT    => 'conn_handler',
		      ),
		    },

    conn_handler => sub {
      if ($_[ARG0]->{ERROR}) {
	print 'conn error: ',$_[ARG0]->{ERROR},"\n";
        # unsuccessful attemps to close the session
	$_[KERNEL]->signal($_[SESSION],'INT');
	$_[KERNEL]->post('SimpleDBI','shutdown');
      } else {
        # this is ok
        print 'connecting to db',"\n";
        $_[KERNEL]->post('SimpleDBI','shutdown');
      }
    },
		   },
		    );

POE::Kernel->run();
exit;


-- 
Radek