File Coverage

blib/lib/Message/Passing/AMQP/Role/DeclaresExchange.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Message::Passing::AMQP::Role::DeclaresExchange;
2 1     1   490 use Moose::Role;
  1         2  
  1         7  
3 1     1   3951 use Moose::Util::TypeConstraints;
  1         2  
  1         7  
4 1     1   1509 use Scalar::Util qw/ weaken /;
  1         1  
  1         70  
5 1     1   8 use namespace::autoclean;
  1         2  
  1         7  
6              
7             with 'Message::Passing::AMQP::Role::HasAChannel';
8              
9             has exchange_name => (
10             is => 'ro',
11             required => 1,
12             isa => 'Str',
13             );
14              
15             has exchange_type => (
16             is => 'ro',
17             isa => enum([qw/ topic direct fanout /]),
18             default => 'topic',
19             );
20              
21             has exchange_durable => (
22             is => 'ro',
23             isa => 'Bool',
24             default => 1,
25             );
26              
27             has _exchange => (
28             is => 'ro',
29             writer => '_set_exchange',
30             predicate => '_has_exchange',
31             );
32              
33             after _set_channel => sub {
34             my $self = shift;
35             weaken($self);
36             $self->_channel->declare_exchange(
37             type => $self->exchange_type,
38             durable => $self->exchange_durable,
39             exchange => $self->exchange_name,
40             on_success => sub {
41             $self->_set_exchange(shift()->method_frame);
42             },
43             on_failure => sub {
44             $self->_clear_channel;
45             },
46             );
47             };
48              
49             1;
50              
51             =head1 NAME
52              
53             Message::Passing::AMQP::Role::DeclaresExchange - Role for instances which have an AMQP exchange.
54              
55             =head1 ATTRIBUTES
56              
57             =head2 exchange_name
58              
59             Defines the exchange name, required.
60              
61             =head2 exchange_type
62              
63             Is one of topic, direct or fanout, defaults to topic.
64              
65             =head2 exchange_durable
66              
67             Defines if the exchange is durable, defaults to true.
68              
69             =head1 AUTHOR, COPYRIGHT AND LICENSE
70              
71             See L<Message::Passing::AMQP>.
72              
73             =cut