1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
package Message::Passing::AMQP::Role::HasAChannel;
use Moose::Role;
use Scalar::Util qw/ weaken /;
use AnyEvent;
use AnyEvent::RabbitMQ;
use namespace::autoclean;
with 'Message::Passing::AMQP::Role::HasAConnection';
has _channel => (
is => 'ro',
writer => '_set_channel',
clearer => '_clear_channel',
);
sub connected {
my ($self, $connection) = @_;
weaken($self);
$connection->open_channel(
on_success => sub {
my $channel = shift;
$self->_set_channel($channel);
},
on_failure => sub {
$self->_clear_channel;
},
on_close => sub {
$self->_clear_channel;
},
);
}
sub disconnected {}
1;
=head1 NAME
Message::Passing::AMQP::HasAChannel - Role for instances which have an AMQP channel.
=head1 ATTRIBUTES
=head1 METHODS
=head2 connected
Called when the channel has connected
=head2 disconnected
Called when the channel disconnects.
=head1 AUTHOR, COPYRIGHT AND LICENSE
See L<Message::Passing::AMQP>.
=cut
|