Net::Stomp::MooseHelpers::CanSubscribe - role for classes that subscribe via Net::Stomp
version 2.6
package MyThing; use Moose; with 'Net::Stomp::MooseHelpers::CanConnect'; with 'Net::Stomp::MooseHelpers::CanSubscribe'; use Try::Tiny; sub foo { my ($self) = @_; $self->connect(); $self->subscribe(); do_something( $self->connection->receive_frame() ); }
This role provides your class with a flexible way to define subscriptions to a STOMP server, and to actually subscribe.
NOTE: as shown in the synopsis, you need 2 separate calls the with, otherwise the roles won't apply. The reason is that this role requires a connection attribute, that is provided by Net::Stomp::MooseHelpers::CanConnect, but the role dependency resolution does not notice that.
with
connection
subscribe_headers
Global setting for subscription headers (passed to "subscribe" in Net::Stomp). Can be overridden by the subscribe_headers slot in each element of "servers" and by the headers slot in each element fof "subscriptions". Defaults to the empty hashref.
headers
subscriptions
A SubscriptionConfigList, that is, an arrayref of hashrefs, each of which describes a subscription. Defaults to the empty arrayref. You should set this value to something useful, otherwise your connection will not receive any message.
subscribe
Call "subscribe_single" method for each element of "subscriptions", passing the generic "subscribe_headers", the per-server subscribe headers (from current_server, slot subscribe_headers) and the per-subscription subscribe headers (from "subscriptions", slot headers).
Throws a Net::Stomp::MooseHelpers::Exceptions::Stomp if anything goes wrong.
subscribe_single
$self->subscribe_single($subscription,$headers);
Call the subscribe method on "connection", passing the $headers.
$headers
You can override or modify this method in your class if you need to perform more work on each subscription.
Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>
This software is copyright (c) 2014 by Net-a-porter.com.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Net::Stomp::MooseHelpers, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Stomp::MooseHelpers
CPAN shell
perl -MCPAN -e shell install Net::Stomp::MooseHelpers
For more information on module installation, please visit the detailed CPAN module installation guide.