| 1 | package Message::Passing::Role::HasAConnection; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Module::Runtime qw/ require_module /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp qw/ confess /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | with qw/ | |||||||||||||||||||||||||||
| 8 | Message::Passing::Role::HasTimeoutAndReconnectAfter | ||||||||||||||||||||||||||||
| 9 | Message::Passing::Role::HasErrorChain | ||||||||||||||||||||||||||||
| 10 | /; | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # requires qw/ _connection_manager_attributes _connection_manager_class /; | ||||||||||||||||||||||||||||
| 13 | 2 | requires 'connected'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has connection_manager => ( | |||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||
| 17 | lazy => 1, | ||||||||||||||||||||||||||||
| 18 | # isa => duck_type([qw/subscribe_to_connect/]), | ||||||||||||||||||||||||||||
| 19 | builder => '_build_connection_manager', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub _build_connection_manager { | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_connection_manager: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | confess "Cannot auto-build this connection manager" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->can("_connection_manager_attributes") and $self->can("_connection_manager_class")
MC/DC0%0/2
$self->can("_connection_manager_attributes") and $self->can("_connection_manager_class")
$self->can("_connection_manager_attributes")
$self->can("_connection_manager_class")
Truth table0%0/3
A and B
A= $self->can("_connection_manager_attributes")B= $self->can("_connection_manager_class")
| |||||||||||||||||||||||||||||
| 25 | unless $self->can('_connection_manager_attributes') | ||||||||||||||||||||||||||||
| 26 | && $self->can('_connection_manager_class'); | ||||||||||||||||||||||||||||
| 27 | 0 | my %attrs = map { $_ => $self->$_ } (@{ $self->_connection_manager_attributes }, qw/timeout reconnect_after error/); | |||||||||||||||||||||||||||
| 28 | 0 | my $class = $self->_connection_manager_class; | |||||||||||||||||||||||||||
| 29 | 0 | require_module($class); | |||||||||||||||||||||||||||
| 30 | 0 | $class->new(%attrs); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ▶ | sub BUILD {} | |||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | after BUILD => sub { | ||||||||||||||||||||||||||||
| 35 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 1 | $self->connection_manager->subscribe_to_connect($self); | |||||||||||||||||||||||||||
| 37 | 2 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | 1; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 NAME | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Message::Passing::Role::HasAConnection - Role for components which have a connection | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Provides a standard ->connection_manager attribute for inputs or outputs which need to | ||||||||||||||||||||||||||||
| 48 | make a network connection before they can send or receive messages. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | The connection manager object is assumed to have the C<< ->subscribe_to_connect >> method | ||||||||||||||||||||||||||||
| 51 | (from L<Message::Passing::Role::Connection>). | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 REQUIRED METHODS | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head2 _build_connection_manager | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Will be called at BUILD (i.e. object construction) time, should return | ||||||||||||||||||||||||||||
| 58 | a connection manager object (i.e. an object that C<< ->subscribe_to_connect >> | ||||||||||||||||||||||||||||
| 59 | can be called on). | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 connected ($client) | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Called by the connection manager when a connection is made. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Usually used to do things like subscribe to queues.. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 OPTIONAL METHODS | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 disconnected ($client) | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | The client received an error or otherwise disconnected. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head2 connection_manager | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Holds the connection manger returned by the C<_build_connection_manager> method. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 WRAPPED METHODS | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head2 BUILD | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Is wrapped to build the connection manager object. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =over | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =item L<Message::Passing::Role::ConenctionManager>. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =back | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 SPONSORSHIP | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | This module exists due to the wonderful people at Suretec Systems Ltd. | ||||||||||||||||||||||||||||
| 96 | <http://www.suretecsystems.com/> who sponsored its development for its | ||||||||||||||||||||||||||||
| 97 | VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with | ||||||||||||||||||||||||||||
| 98 | the SureVoIP API - | ||||||||||||||||||||||||||||
| 99 | <http://www.surevoip.co.uk/support/wiki/api_documentation> | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 AUTHOR, COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | See L<Message::Passing>. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||