| 1 | package Net::Async::AMQP::Server; | ||||||||||||||||||||
| 2 | 2 | $Net::Async::AMQP::Server::VERSION = '2.000'; | |||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use parent qw(IO::Async::Listener); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | Net::Async::AMQP::Server | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | version 2.000 | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 2 | ▶ | use curry; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 2 | ▶ | use IO::Socket::IP; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 2 | ▶ | use Variable::Disposition qw(retain_future); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | ▶ | use Net::Async::AMQP::Server::Connection; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head2 configure | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | Set up the instance. | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | Takes the following named parameters: | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =over 4 | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =item * local_host | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =item * port | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =back | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 2 | ▶ | sub configure { | ||||||||||||||||||
|
Subroutine
configure: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 45 | 2 | my ($self, %args) = @_; | |||||||||||||||||||
| 46 | 2 | $self->{$_} = delete $args{$_} for qw/local_host port/; | |||||||||||||||||||
| 47 | 2 | return $self->SUPER::configure(%args); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =head2 local_host | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Accessor for the current local_host setting. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | sub local_host { shift->{local_host} } | ||||||||||||||||||
|
Subroutine
local_host: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head2 port | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | Accessor for the current port setting | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | ▶ | sub port { shift->{port} } | ||||||||||||||||||
|
Subroutine
port: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head2 listening | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | Resolves with the listener. | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 2 | ▶ | sub listening { | ||||||||||||||||||
|
Subroutine
listening: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 73 | 2 | my $self = shift; | |||||||||||||||||||
| 74 | 2 | ▶ | $self->{listening} ||= $self->loop->new_future | ||||||||||||||||||
|
Condition66%2/3
$self->{"listening"} ||= $self->loop->new_future
MC/DC0%0/2
$self->{"listening"} ||= $self->loop->new_future
$self->{"listening"}
$self->loop->new_future
Truth table66%2/3
A ||= B
A= $self->{"listening"}B= $self->loop->new_future
| |||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =head2 notifier_name | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | ▶ | sub notifier_name { | ||||||||||||||||||
|
Subroutine
notifier_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||
| 83 | 0 | 'NaAMQPServer=' . join ':', $self->local_host, $self->port | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head2 on_listen | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | Called when we have a listening socket. | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | ▶ | sub on_listen { | ||||||||||||||||||
|
Subroutine
on_listen: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 93 | 1 | my $self = shift; | |||||||||||||||||||
| 94 | 1 | my ($host, $port) = $self->read_handle->sockhost_service($self->sockname); | |||||||||||||||||||
| 95 | 1 | $self->{port} = $port; | |||||||||||||||||||
| 96 | 1 | $self->{local_host} = $host; | |||||||||||||||||||
| 97 | $self->listening->done( | ||||||||||||||||||||
| 98 | $self->{local_host}, | ||||||||||||||||||||
| 99 | $self->{port} | ||||||||||||||||||||
| 100 | ) | ||||||||||||||||||||
| 101 | 1 | } | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =head2 _add_to_loop | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 1 | ▶ | sub _add_to_loop { | ||||||||||||||||||
|
Subroutine
_add_to_loop: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 108 | 1 | my ($self, $loop) = @_; | |||||||||||||||||||
| 109 | 1 | $self->SUPER::_add_to_loop($loop); | |||||||||||||||||||
| 110 | retain_future( | ||||||||||||||||||||
| 111 | $self->listen( | ||||||||||||||||||||
| 112 | addr => { | ||||||||||||||||||||
| 113 | family => 'inet', | ||||||||||||||||||||
| 114 | socktype => 'stream', | ||||||||||||||||||||
| 115 | port => $self->port, | ||||||||||||||||||||
| 116 | ip => ($self->local_host // '0.0.0.0'), | ||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||
| 118 | 1 | ▶ | )->then(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 119 | 1 | $self->on_listen; | |||||||||||||||||||
| 120 | }) | ||||||||||||||||||||
| 121 | 1 | ▶ | ) | ||||||||||||||||||
|
Condition50%1/2
$self->local_host // "0.0.0.0"
MC/DC0%0/1
$self->local_host // "0.0.0.0"
$self->local_host
Truth table50%1/2
A
A= $self->local_host
| |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head2 on_accept | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 1 | ▶ | sub on_accept { | ||||||||||||||||||
|
Subroutine
on_accept: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 129 | 1 | my ($self, $sock) = @_; | |||||||||||||||||||
| 130 | { | ||||||||||||||||||||
| 131 | 1 | my $host = $sock->peerhost; | |||||||||||||||||||
| 132 | 1 | my $port = $sock->peerport; | |||||||||||||||||||
| 133 | 1 | $self->debug_printf("New connection from %s:%d", $host, $port); | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 1 | my $stream = Net::Async::AMQP::Server::Connection->new( | |||||||||||||||||||
| 137 | handle => $sock, | ||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||
| 139 | 1 | $self->add_child($stream); | |||||||||||||||||||
| 140 | } | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 2 | 1; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||