| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||
| 3 | # | ||||||||||
| 4 | # (C) Paul Evans, 2010-2011 -- leonerd@leonerd.org.uk | ||||||||||
| 5 | |||||||||||
| 6 | package Net::Async::Tangence::Server; | ||||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | ▶ | use IO::Async::Listener '0.36'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | ▶ | use base qw( IO::Async::Listener ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 4 | our $VERSION = '0.14'; | |||||||||
| 15 | |||||||||||
| 16 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 4 | ▶ | use Net::Async::Tangence::ServerProtocol; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | =head1 NAME | ||||||||||
| 21 | |||||||||||
| 22 | C<Net::Async::Tangence::Server> - serve C<Tangence> clients using C<IO::Async> | ||||||||||
| 23 | |||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||
| 25 | |||||||||||
| 26 | This subclass of L<IO::Async::Listener> accepts L<Tangence> client | ||||||||||
| 27 | connections. | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | =head1 PARAMETERS | ||||||||||
| 32 | |||||||||||
| 33 | The following named parameters may be passed to C<new> or C<configure>: | ||||||||||
| 34 | |||||||||||
| 35 | =over 8 | ||||||||||
| 36 | |||||||||||
| 37 | =item registry => Tangence::Registry | ||||||||||
| 38 | |||||||||||
| 39 | The L<Tangence::Registry> for the server's objects. | ||||||||||
| 40 | |||||||||||
| 41 | =back | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | sub _init | ||||||||||
| 46 | { | ||||||||||
| 47 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||
| 48 | 3 | my ( $params ) = @_; | |||||||||
| 49 | |||||||||||
| 50 | $params->{handle_constructor} = sub { | ||||||||||
| 51 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 52 | |||||||||||
| 53 | return Net::Async::Tangence::ServerProtocol->new( | ||||||||||
| 54 | registry => $self->{registry}, | ||||||||||
| 55 | on_closed => $self->_capture_weakself( sub { | ||||||||||
| 56 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 2 | $self->remove_child( $_[0] ); | |||||||||
| 58 | 4 | } ), | |||||||||
| 59 | ); | ||||||||||
| 60 | 3 | }; | |||||||||
| 61 | |||||||||||
| 62 | 3 | $self->SUPER::_init( $params ); | |||||||||
| 63 | |||||||||||
| 64 | 3 | ▶ | $self->{registry} = delete $params->{registry} if exists $params->{registry}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | sub on_accept | ||||||||||
| 68 | { | ||||||||||
| 69 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
on_accept: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 70 | 4 | my ( $conn ) = @_; | |||||||||
| 71 | |||||||||||
| 72 | 4 | $self->add_child( $conn ); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | # Useful for testing | ||||||||||
| 76 | sub make_new_connection | ||||||||||
| 77 | { | ||||||||||
| 78 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
make_new_connection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 79 | 4 | my ( $sock ) = @_; | |||||||||
| 80 | |||||||||||
| 81 | # Mass cheating | ||||||||||
| 82 | 4 | my $conn = $self->{handle_constructor}->( $self ); | |||||||||
| 83 | |||||||||||
| 84 | 4 | $conn->configure( handle => $sock ); | |||||||||
| 85 | 4 | $self->on_accept( $conn ); | |||||||||
| 86 | |||||||||||
| 87 | 4 | return $conn; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | =head1 AUTHOR | ||||||||||
| 91 | |||||||||||
| 92 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||
| 93 | |||||||||||
| 94 | =cut | ||||||||||
| 95 | |||||||||||
| 96 | 4 | 0x55AA; | |||||||||