NAME

Role::Pg::Notify - Client PostgreSQL notification Role

VERSION

version 0.001

DESCRIPTION

This role adds easy notification to client programs connected to a PostgreSQL database.

NAME

Role::Pg::Notify

ATTRIBUTES

notify_dbh

Role::Pg::Notify tries to guess your dbh. If it isn't a standard DBI::db named dbh, or constructed in a DBIx::Class schema called schema, you have to return the dbh from _build_notify_dbh.

METHODS

listen

$self->listen( queue => 'queue_name' );
$self->listen( queue => \@queues );

Sets up the listener. Quit listening to the named queues.

Returns undef immediately if no queue is provided.

unlisten

$self->unlisten( queue => 'queue_name' );
$self->unlisten( queue => \@queues );

Quit listening to the named queues.

Returns undef immediately if no queue is provided.

notify

$self->notify( queue => 'queue_name' );
$self->notify( queue => 'queue_name', payload => $data  );

Sends an asynchronous notification to the named queue, with an optional payload.

Returns undef immediately if no queue name is provided.

get_notification

my $notifies = $self->get_notification();

Retrievies the pending notifications. The return value is an arrayref where each row looks like this:

my ($name, $pid, $payload) = @$notify;

Returns undef if no notification was found.

set_listen

my $notifies = $self->set_listen($timeout);

Retrievies the pending notifications. The return value is an arrayref where each row looks like this:

my ($name, $pid, $payload) = @$notify;

If no notification is found, set_listen listens $timeout seconds. If any notification to any queue we're listening on is received, it will be returned immediately.

Not passing $timeout (or passing undef) means that set_listen will wait forever (or until a notification is received).

Returns undef if no notification was received within the requested time.

AUTHOR

Kaare Rasmussen <kaare@cpan.org>.

COPYRIGHT

Copyright (C) 2014, Kaare Rasmussen

This module is free software; you can redistribute it or modify it under the same terms as Perl itself.

AUTHOR

Kaare Rasmussen <kaare at cpan dot net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Kaare Rasmussen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.