| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | |||
| 4 | package Jifty::Plugin::PubSub::Bus; | ||
| 5 | use base qw/ AnyMQ /; | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Jifty::Plugin::PubSub::Bus - AnyMQ class for Jifty | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | This class inherits from L<AnyMQ>, and exists to provide a simpler | ||
| 14 | interface to that module. | ||
| 15 | |||
| 16 | =head1 METHODS | ||
| 17 | |||
| 18 | =head2 publish I<TOPIC> I<DATA> | ||
| 19 | |||
| 20 | Jifty uses the C<type> key of data on the L<AnyMQ> bus to track what | ||
| 21 | topic the data was originally published on; this method checks that the | ||
| 22 | provided I<DATA> doesn't attempt to use that key, and warns if it does. | ||
| 23 | It then publishes the given I<DATA> on the I<TOPIC>. | ||
| 24 | |||
| 25 | Roughly equivalent to L<AnyMQ/topic> followed by | ||
| 26 | L<AnyMQ::Topic/publish>. | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | sub publish { | ||
| 31 | my $self = shift; | ||
| 32 | my ($topic, $data) = @_; | ||
| 33 | |||
| 34 | $data ||= {}; | ||
| 35 | |||
| 36 | warn "Publish passed data which uses the reserved 'type' key" | ||
| 37 | if exists $data->{type}; | ||
| 38 | |||
| 39 | $data->{type} = $topic; | ||
| 40 | $self->topic( $topic )->publish( $data ); | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; |