.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "IPC::PubSub 3pm" .TH IPC::PubSub 3pm "2018-01-15" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" IPC::PubSub \- Interprocess Publish/Subscribe channels .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # A new message bus with the DBM::Deep backend \& # (Other possible backends include Memcached and PlainHash) \& my $bus = IPC::PubSub\->new(DBM_Deep => \*(Aq/tmp/pubsub.db\*(Aq); \& \& # A channel is any arbitrary string \& my $channel = \*(Aq#perl6\*(Aq; \& \& # Register a new publisher (you can publish to multiple channels) \& my $pub = $bus\->new_publisher("#perl6", "#moose"); \& \& # Publish a message (may be a complex object) to those channels \& $pub\->msg("This is a message"); \& \& # Register a new subscriber (you can subscribe to multiple channels) \& my $sub = $bus\->new_subscriber("#moose"); \& \& # Publish an object to channels \& $pub\->msg("This is another message"); \& \& # Set all subsequent messages from this publisher to expire in 30 seconds \& $pub\->expiry(30); \& $pub\->msg("This message will go away in 30 seconds"); \& \& # Simple get: Returns the messages sent since the previous get, \& # but only for the first channel. \& my @msgs = $sub\->get; \& \& # Simple get, with an explicit channel key (must be among the ones \& # it initially subscribed to) \& my @moose_msgs = $sub\->get("#moose"); \& \& # Complex get: Returns a hash reference from channels to array \& # references of [timestamp, message]. \& my $hash_ref = $sub\->get_all; \& \& # Changing the list of channels we subscribe to \& $sub\->subscribe(\*(Aqsome\-other\-channel\*(Aq); \& $sub\->unsubscribe(\*(Aqsome\-other\-channel\*(Aq); \& \& # Changing the list of channels we publish to \& $pub\->publish(\*(Aqsome\-other\-channel\*(Aq); \& $pub\->unpublish(\*(Aqsome\-other\-channel\*(Aq); \& \& # Listing and checking if we are in a channel \& my @sub_channels = $sub\->channels; \& my @pub_channels = $pub\->channels; \& print "Sub is in #moose" if $sub\->channels\->{\*(Aq#moose\*(Aq}; \& print "Pub is in #moose" if $pub\->channels\->{\*(Aq#moose\*(Aq}; \& \& # Raw cache manipulation APIs (not advised; use \->modify instead) \& $bus\->lock(\*(Aqchannel\*(Aq); \& $bus\->unlock(\*(Aqchannel\*(Aq); \& my @timed_msgs = $bus\->fetch(\*(Aqkey1\*(Aq, \*(Aqkey2\*(Aq, \*(Aqkey3\*(Aq); \& $bus\->store(\*(Aqkey\*(Aq, \*(Aqvalue\*(Aq, time, 30); \& \& # Atomic updating of cache content; $_ is stored back on the \& # end of the callback. \& my $rv = $bus\->modify(\*(Aqkey\*(Aq => sub { delete $_\->{foo} }); \& \& # Shorthand for $bus\->modify(\*(Aqkey\*(Aq => sub { $_ = \*(Aqval\*(Aq }); \& $bus\->modify(\*(Aqkey\*(Aq => \*(Aqval\*(Aq); \& \& # Shorthand for $bus\->modify(\*(Aqkey\*(Aq => sub { $_ }); \& $bus\->modify(\*(Aqkey\*(Aq); \& \& # Disconnect the backend connection explicitly \& $bus\->disconnect; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a simple \s-1API\s0 for publishing messages to \fIchannels\fR and for subscribing to them. .PP When a \fImessage\fR is published on a channel, all subscribers currently in that channel will get it on their next \f(CW\*(C`get\*(C'\fR or \f(CW\*(C`get_all\*(C'\fR call. .PP Currently, it offers four backends: \f(CW\*(C`DBM_Deep\*(C'\fR for on-disk storage, \&\f(CW\*(C`Memcached\*(C'\fR for possibly multi-host storage, \f(CW\*(C`Jifty::DBI\*(C'\fR for database-backed storage, and \f(CW\*(C`PlainHash\*(C'\fR for single-process storage. .PP Please see the tests in \fIt/\fR for this distribution, as well as \*(L"\s-1SYNOPSIS\*(R"\s0 above, for some usage examples; detailed documentation is not yet available. .SH "SEE ALSO" .IX Header "SEE ALSO" IPC::DirQueue, where the subscribers divide the published messages among themselves, so different subscribers never see the same message. .SH "AUTHORS" .IX Header "AUTHORS" Audrey Tang .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2006, 2007 by Audrey Tang . .PP This software is released under the \s-1MIT\s0 license cited below. .ie n .SS "The ""\s-1MIT""\s0 License" .el .SS "The ``\s-1MIT''\s0 License" .IX Subsection "The MIT License" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \*(L"Software\*(R"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: .PP The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. .PP \&\s-1THE SOFTWARE IS PROVIDED \*(L"AS IS\*(R", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\s0