POE::Component::SimpleDBI

Asynchronous non-blocking DBI calls in POE made simple
Download

POE::Component::SimpleDBI Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Apocalypse
  • Publisher web site:
  • http://search.cpan.org/~apocal/

POE::Component::SimpleDBI Tags


POE::Component::SimpleDBI Description

Asynchronous non-blocking DBI calls in POE made simple POE::Component::SimpleDBI is a Perl module that works its magic by creating a new session with POE, then spawning off a child process to do the "heavy" lifting. That way, your main POE process can continue servicing other clients. Queries are put into a queue, and processed one at a time.The standard way to use this module is to do this: use POE; use POE::Component::SimpleDBI; POE::Component::SimpleDBI->new( ... ); POE::Session->create( ... ); POE::Kernel->run();SYNOPSIS use POE; use POE::Component::SimpleDBI; # Create a new session with the alias we want POE::Component::SimpleDBI->new( 'SimpleDBI' ) or die 'Unable to create the DBI session'; # Create our own session to communicate with SimpleDBI POE::Session->create( inline_states => { _start => sub { # Tell SimpleDBI to connect $_->post( 'SimpleDBI', 'CONNECT', 'DSN' => 'DBI:mysql:database=foobaz;host=192.168.1.100;port=3306', 'USERNAME' => 'FooBar', 'PASSWORD' => 'SecretPassword', 'EVENT' => 'conn_handler', ); # Execute a query and return number of rows affected $_->post( 'SimpleDBI', 'DO', 'SQL' => 'DELETE FROM FooTable WHERE ID = ?', 'PLACEHOLDERS' => , 'EVENT' => 'deleted_handler', 'INSERT_ID' => 0, ); # Retrieve one row of information $_->post( 'SimpleDBI', 'SINGLE', 'SQL' => 'Select * from FooTable LIMIT 1', 'EVENT' => 'success_handler', 'BAGGAGE' => 'Some Stuff I want to keep!', ); # We want many rows of information + get the query ID so we can delete it later # Furthermore, disable prepare_cached on this query my $id = $_->call( 'SimpleDBI', 'MULTIPLE', 'SQL' => 'SELECT foo, baz FROM FooTable2 WHERE id = ?', 'PLACEHOLDERS' => , 'EVENT' => 'multiple_handler', 'PREPARE_CACHED'=> 0, ); # Quote something and send it to another session $_->post( 'SimpleDBI', 'QUOTE', 'SQL' => 'foo$*@%%sdkf"""', 'SESSION' => 'OtherSession', 'EVENT' => 'quote_handler', ); # Changed our mind! $_->post( 'SimpleDBI', 'Delete_Query', $id ); # 3 ways to shutdown # This will let the existing queries finish, then shutdown $_->post( 'SimpleDBI', 'shutdown' ); # This will terminate when the event traverses # POE's queue and arrives at SimpleDBI $_->post( 'SimpleDBI', 'shutdown', 'NOW' ); # Even QUICKER shutdown :) $_->call( 'SimpleDBI', 'shutdown', 'NOW' ); }, # Define your request handlers here 'quote_handler' => \&FooHandler, # And so on }, ); Requirements: · Perl


POE::Component::SimpleDBI Related Software