#  You may distribute under the terms of either the GNU General Public License
#  or the Artistic License (the same terms as Perl itself)
#
#  (C) Paul Evans, 2010-2020 -- leonerd@leonerd.org.uk

package Net::Async::Tangence::ServerProtocol 0.16;

use v5.14;
use warnings;

use base qw( Net::Async::Tangence::Protocol Tangence::Server );
use mro 'c3';

use Carp;

=head1 NAME

C<Net::Async::Tangence::ServerProtocol> - C<Net::Async::Tangence::Protocol>
subclass for servers

=head1 DESCRIPTION

This subclass of L<Net::Async::Tangence::Protocol> provides additional logic
required by the server side of a connection. It is not intended to be directly
used by server implementations.

=cut

sub _init
{
   my $self = shift;
   my ( $params ) = @_;

   $self->registry( delete $params->{registry} );

   $params->{on_closed} ||= undef;

   $self->SUPER::_init( $params );
}

sub configure
{
   my $self = shift;
   my %params = @_;

   if( exists $params{on_closed} ) {
      my $on_closed = $params{on_closed};
      $params{on_closed} = sub {
         my $self = shift;

         $on_closed->( $self ) if $on_closed;
      };
   }

   $self->SUPER::configure( %params );
}

sub rootobj
{
   my $self = shift;
   my ( $identity ) = @_;

   return $self->parent->conn_rootobj( $self, $identity );
}

sub permit_registry
{
   my $self = shift;
   return $self->parent->conn_permits_registry( $self );
}

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut

0x55AA;
