File Coverage

blib/lib/Hoppy/TCPHandler/Disconnected.pm
Criterion Covered Total %
statement 22 23 95.6
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 29 32 90.6


line stmt bran cond sub pod time code
1             package Hoppy::TCPHandler::Disconnected;
2 7     7   38 use strict;
  7         11  
  7         217  
3 7     7   34 use warnings;
  7         14  
  7         173  
4 7     7   30 use base qw( Hoppy::Base );
  7         12  
  7         2903  
5              
6             sub do_handle {
7 1     1 1 13 my $self = shift;
8 1         3 my $poe = shift;
9 1         9 my $c = $self->context;
10 1         23 my $session_id = $poe->session->ID;
11 1         9 my $user = $c->room->fetch_user_from_session_id($session_id);
12 1         3 my $user_id;
13 1 50       4 if ($user) {
14 1         5 $user_id = $user->user_id;
15 1         7 $c->room->logout( { user_id => $user_id }, $poe );
16             }
17 1         5 delete $c->{sessions}->{$session_id};
18 1         2 delete $c->{not_authorized}->{$session_id};
19 1         5 $poe->kernel->yield("shutdown");
20 1 50       70 if ( my $hook = $c->hook->{client_disconnected} ) {
21 0           $hook->work( { poe => $poe, user_id => $user_id } );
22             }
23             }
24              
25             1;
26             __END__