summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README3
-rw-r--r--lib/POE/Component/Pg.pm87
2 files changed, 68 insertions, 22 deletions
diff --git a/README b/README
index c2cd558..4ab5756 100644
--- a/README
+++ b/README
@@ -24,9 +24,8 @@ DEPENDENCIES
TODO
- - Object interface
- Argument validation
- - Test suite
+ - Larger test suite
- Documentation
- Transaction support?
- Timeouts?
diff --git a/lib/POE/Component/Pg.pm b/lib/POE/Component/Pg.pm
index 8232414..f6018d6 100644
--- a/lib/POE/Component/Pg.pm
+++ b/lib/POE/Component/Pg.pm
@@ -4,39 +4,85 @@ package POE::Component::Pg;
use strict;
use POE;
-use DBI;
-use DBD::Pg ':async';
our $VERSION = '0.1';
-sub QACT { 0 }
-sub QQUERY { 1 }
-sub QPARAM { 2 }
-sub QSESID { 3 }
-sub QEVENT { 4 }
-sub QARG { 5 }
+
+# ---------------------
+# C O N S T R U C T O R
sub spawn {
my($class, %args) = @_;
- return POE::Session->create(
- package_states => [ $class => [qw|
+
+ my $self = bless {
+ %args,
+ dbi => undef,
+ events => [], # [ [ sess_id, local_event, remote_event ], .. ]
+ queue => [],
+ listen => [], # [ [ sess_id, pgsql_event, remote_event ], .. ]
+ state => 0, # 0=idle, 1=write, 2=read
+ shutdown => 0,
+ }, $class;
+
+ my $s = POE::Session->create(
+ package_states => [ $class.'::STATES' => [qw|
_start register unregister connect listen query do addqueue shutdown process_queue dbi_canread dbi_canwrite
|]],
- heap => {
- %args,
- dbi => undef,
- events => [], # [ [ sess_id, local_event, remote_event ], .. ]
- queue => [],
- listen => [], # [ [ sess_id, pgsql_event, remote_event ], .. ]
- state => 0, # 0=idle, 1=write, 2=read
- shutdown => 0,
- },
- );
+ heap => $self,
+ ) or return undef;
+
+ return $self;
}
+
+
+# -------------
+# M E T H O D S
+
+
+sub dbi_handle {
+ return shift->{dbi};
+}
+
+
+sub session_id {
+ return shift->{session_id};
+}
+
+
+sub yield {
+ $poe_kernel->post(shift->session_id, @_);
+}
+
+
+sub call {
+ $poe_kernel->call(shift->session_id, @_);
+}
+
+
+
+
+# ---------
+# I N P U T
+
+
+package POE::Component::Pg::STATES;
+
+use POE;
+use DBI;
+use DBD::Pg ':async';
+
+sub QACT { 0 }
+sub QQUERY { 1 }
+sub QPARAM { 2 }
+sub QSESID { 3 }
+sub QEVENT { 4 }
+sub QARG { 5 }
+
+
# non-POE helper function
sub sendevent {
my($obj, $event, @arg) = @_;
@@ -47,6 +93,7 @@ sub sendevent {
sub _start {
$_[KERNEL]->alias_set($_[HEAP]{alias});
+ $_[HEAP]{session_id} = $_[SESSION]->ID();
}