NAME

POE::Component::DBIx::MyServer - A pseudo mysql POE server

DESCRIPTION

This modules helps building a server that can communicates with mysql clients.

Experimental now.

There is a small proxy that actually connect to another mysql server via DBI and returns the result of sql requests. It actually works not very correctly since a few mysql specific stuff are not handled properly and since it return stuff from selects.

SYNOPSYS

First you create a server subclass that will redefine the change_db method.

package MyServer;

use POE;
use base 'POE::Component::DBIx::MyServer';

sub change_db {
    my $class = shift;
    my ($client, $data) = @_;

    if (Class::Inspector->installed($class."::".$data)) {
        $client->isa($class."::".$data);
    }
}

In the example the MyServer shipped uses various perl classes as DB handlers. Maybe it's possible to deal with it differently and change_db in some other way.

Then you can create various classes (that subclass the PoCo::DBIx::MyServer::Client class) that will behave as databases in your mysql server.

package MyServer::HelloWorld;

use POE;

sub resolve_query {
    my ($self, $query) = @_;
    my $event = $self->resolve_sys_query($query);

    if ($event) {
        return $event;
    }
    else {
        return 'hello_world_event';
    }
}

sub hello_world_event {
    my ( $kernel, $session, $heap, $self ) = @_[ KERNEL, SESSION, HEAP, OBJECT];
    my $data = $_[ARG0];

    $self->send_results(['column1'], [['Hello World from a perl mysql DB !']]);
}

1;

In those classes you have to redefine the resolver method in which you can resolve queries to events name (by returning the event name). Then you implement events as methods (with special POE stuff, check the samples).

Make sure to resolve the system queries otherwise you won't be able to connect to the server in the first place.

Then you can use the send_results method (which is a wrapper around _send_definitions and _send_rows) to send data to the client.

There are also a bunch of other methods to send empty resultsets or ok for queries that don't return results.

AUTHORS

Eriam Schaffter, eriam@cpan.org and original work done by Philip Stoev in the DBIx::MyServer module.

COPYRIGHT

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.