lib/auto/share/dist/App-SocialCalc-Multiplayer/third-party/lib/PocketIO/Transport/Base.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 109 CC 4 SCAR 11.0
CC
4
Cov
0%
client_connected
6.0
_log_client_connected
6.0
_log_client_disconnected
6.0
CRAP 3.0
1 package PocketIO::Transport::Base;
2  
3 use strict;
4 use warnings;
5  
6 use JSON ();
7 use Encode ();
8 use Try::Tiny;
9 use Scalar::Util qw(weaken);
10  
11 use Plack::Request;
12 use PocketIO::Handle;
13 use PocketIO::Pool;
14  
15 sub new {
16 my $class = shift;
17  
18 my $self = bless {@_}, $class;
19  
20 weaken $self->{env};
21 $self->{req} = Plack::Request->new($self->{env});
22  
23 return $self;
24 }
25  
26 sub req { shift->{req} }
27 sub env { shift->{req}->{env} }
28  
29 sub add_connection {
30 my $self = shift;
31  
32 return PocketIO::Pool->add_connection(type => $self->name, req => $self->{req}, @_);
33 }
34  
35 sub remove_connection {
36 my $self = shift;
37  
38 PocketIO::Pool->remove_connection($_[0]);
39  
40 return $self;
41 }
42  
43 sub find_connection {
44 my $self = shift;
45  
46 return PocketIO::Pool->find_connection(@_);
47 }
48  
49 sub client_connected {
50 my $self = shift;
51 my ($conn) = @_;
52  
53 return if $conn->is_connected;
54  
55 $self->_log_client_connected($conn);
56  
57 $conn->connected;
58 }
59  
60 sub client_disconnected {
61 my $self = shift;
62 my ($conn) = @_;
63  
64 $self->_log_client_disconnected($conn);
65  
66 $conn->disconnected;
67  
68 $self->remove_connection($conn);
69  
70 return $self;
71 }
72  
73 sub _log_client_connected {
74 my $self = shift;
75 my ($conn) = @_;
76  
77 my $logger = $self->_get_logger;
78 return unless $logger;
79  
80 $logger->(
81 { level => 'debug',
82 message => sprintf(
83 "Client '%s' connected via '%s'",
84 $conn->id, $conn->type
85 )
86 }
87 );
88 }
89  
90 sub _log_client_disconnected {
91 my $self = shift;
92 my ($conn) = @_;
93  
94 my $logger = $self->_get_logger;
95 return unless $logger;
96  
97 $logger->(
98 { level => 'debug',
99 message => sprintf("Client '%s' disconnected", $conn->id)
100 }
101 );
102 }
103  
104 sub _get_logger {
105 my $self = shift;
106  
107 return $self->env->{'psgix.logger'};
108 }
109  
110 sub _build_handle {
111 my $self = shift;
112  
113 return PocketIO::Handle->new(@_);
114 }
115  
116 1;
117 __END__