NAME
App::Chart::Glib::Ex::DirBroadcast -- broadcast messages through a directory of named pipes
SYNOPSIS
use App::Chart::Glib::Ex::DirBroadcast;
App::Chart::Glib::Ex::DirBroadcast->directory ('/my/directory');
App::Chart::Glib::Ex::DirBroadcast->listen;
App::Chart::Glib::Ex::DirBroadcast->connect ('my-key', sub { print @_; });
App::Chart::Glib::Ex::DirBroadcast->send ('my-key', "hello\n");
DESCRIPTION
DirBroadcast is a message broadcasting system based on named pipes in a given directory, with a Glib main loop IO watch listening and calling connected handlers. It's intended for use between multiple running copies of a single application so they can notify each other of changes to files etc.
Messages have a string "key" which is a name or type decided by the application, and then any parameters which Storable can handle (Storable). You can have either a single broadcast directory used for all purposes, or create multiple DirBroadcast objects. The method functions described below take either the class name App::Chart::Glib::Ex::DirBroadcast for the single global, or a DirBroadcast object.
FUNCTIONS
App::Chart::Glib::Ex::DirBroadcast->new ($directory)-
Create and return a new DirBroadcast object communicating through the given
$directory.$directoryis created if it doesn't already exist (with acroakif that fails).my $dirb = App::Chart::Glib::Ex::DirBroadcast->new ('/var/run/myapp') App::Chart::Glib::Ex::DirBroadcast->directory ($directory)App::Chart::Glib::Ex::DirBroadcast->directory ()$dirb->directory ($directory)$dirb->directory ()-
Get or set the filesystem directory used for broadcasts.
App::Chart::Glib::Ex::DirBroadcast->send ($key, $data, ...)App::Chart::Glib::Ex::DirBroadcast->send_locally ($key, $data, ...)$dirb->send ($key, $data, ...)$dirb->send_locally ($key, $data, ...)-
Send a message of
$keyand optional$datavalues.sendbroadcasts to all processes, including the current process, orsend_locallyjust to the current process.A send within the current process just means direct calls to functions registered by
connectbelow. This takes place immediately within thesendorsend_locally, there's no queuing and the current process doesn't have to have alistenactive.The data values can be anything
Storablecan freeze (see Storable). Forsend_locallythere's no copying, the values are simply passed to the connected functions, so the values can be anything at all. App::Chart::Glib::Ex::DirBroadcast->listen ()$dirb->listen ()-
Create a named pipe in the broadcast directory to receive messages from other processes, and setup a
Glib::IO->add_watchto call the functions registered withconnectwhen a message is received. App::Chart::Glib::Ex::DirBroadcast->connect ($key, $subr)$dirb->connect ($key, $subr)-
Connect coderef
$subrto be called for messages of$key. The arguments to$subrare the data values passed tosend. App::Chart::Glib::Ex::DirBroadcast->connect_for_object ($key, $objsubr, $obj)$dirb->connect_for_object ($key, $osubr, $obj)-
Connect coderef
$osubrto be called for notifications of$key, for as long as Perl object$objexists.$objis the first argument in each call, followed by the notify data,sub my_func { my ($obj, $data...) = @_; }If
$objis destroyed then$osubris no longer called. Only a weak reference to$objis kept, so just because it wants to hear about some notifications it won't keep it alive forever.