| 1 | package Message::Passing::AMQP::Role::DeclaresExchange; | ||
| 2 | 1 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use Types::Standard qw( Bool Str Enum ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Scalar::Util qw/ weaken /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 1 | with 'Message::Passing::AMQP::Role::HasAChannel'; | |
| 8 | |||
| 9 | 1 | has exchange_name => ( | |
| 10 | is => 'ro', | ||
| 11 | required => 1, | ||
| 12 | isa => Str, | ||
| 13 | ); | ||
| 14 | |||
| 15 | 1 | has exchange_type => ( | |
| 16 | is => 'ro', | ||
| 17 | isa => Enum([qw( topic direct fanout headers )]), | ||
| 18 | default => 'topic', | ||
| 19 | ); | ||
| 20 | |||
| 21 | 1 | has exchange_durable => ( | |
| 22 | is => 'ro', | ||
| 23 | isa => Bool, | ||
| 24 | default => 1, | ||
| 25 | ); | ||
| 26 | |||
| 27 | 1 | has exchange_auto_delete => ( | |
| 28 | is => 'ro', | ||
| 29 | isa => Bool, | ||
| 30 | default => 0, | ||
| 31 | ); | ||
| 32 | |||
| 33 | 1 | has _exchange => ( | |
| 34 | is => 'ro', | ||
| 35 | writer => '_set_exchange', | ||
| 36 | predicate => '_has_exchange', | ||
| 37 | ); | ||
| 38 | |||
| 39 | 0 | ▶ | after _set_channel => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 40 | 0 | my $self = shift; | |
| 41 | 0 | weaken($self); | |
| 42 | $self->_channel->declare_exchange( | ||
| 43 | type => $self->exchange_type, | ||
| 44 | durable => $self->exchange_durable, | ||
| 45 | auto_delete => $self->exchange_auto_delete, | ||
| 46 | exchange => $self->exchange_name, | ||
| 47 | 0 | ▶ | on_success => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 48 | 0 | $self->_set_exchange(shift()->method_frame); | |
| 49 | }, | ||
| 50 | 0 | ▶ | on_failure => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 51 | 0 | $self->_clear_channel; | |
| 52 | }, | ||
| 53 | 0 | ); | |
| 54 | 1 | }; | |
| 55 | |||
| 56 | 1 | 1; | |
| 57 | |||
| 58 | =head1 NAME | ||
| 59 | |||
| 60 | Message::Passing::AMQP::Role::DeclaresExchange - Role for instances which have an AMQP exchange. | ||
| 61 | |||
| 62 | =head1 ATTRIBUTES | ||
| 63 | |||
| 64 | =head2 exchange_name | ||
| 65 | |||
| 66 | Defines the exchange name, required. | ||
| 67 | |||
| 68 | =head2 exchange_type | ||
| 69 | |||
| 70 | Is one of topic, direct, fanout or headers, defaults to topic. | ||
| 71 | |||
| 72 | =head2 exchange_durable | ||
| 73 | |||
| 74 | Defines if the exchange is durable, defaults to true. | ||
| 75 | |||
| 76 | =head2 exchange_auto_delete | ||
| 77 | |||
| 78 | Defines if the exchange will be auto-deleted after the connection is closed, | ||
| 79 | defaults to false. | ||
| 80 | |||
| 81 | =head1 AUTHOR, COPYRIGHT AND LICENSE | ||
| 82 | |||
| 83 | See L<Message::Passing::AMQP>. | ||
| 84 | |||
| 85 | =cut | ||