line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PocketIO; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
275342
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
213
|
|
4
|
5
|
|
|
5
|
|
31
|
use warnings; |
|
5
|
|
|
|
|
54
|
|
|
5
|
|
|
|
|
390
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.17'; |
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
28
|
use overload '&{}' => sub { shift->to_app(@_) }, fallback => 1; |
|
5
|
|
|
3
|
|
20
|
|
|
5
|
|
|
|
|
77
|
|
|
3
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
3874
|
use PocketIO::Exception; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
127
|
|
11
|
5
|
|
|
5
|
|
11178
|
use PocketIO::Resource; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
154
|
|
12
|
5
|
|
|
5
|
|
3184
|
use PocketIO::Pool; |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
3071
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
8
|
|
|
8
|
1
|
4816
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
|
|
|
38
|
my $self = {@_}; |
18
|
8
|
|
|
|
|
111
|
bless $self, $class; |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
35
|
$self->{handler} = $self->_get_handler; |
21
|
|
|
|
|
|
|
|
22
|
7
|
|
50
|
|
|
242
|
$self->{socketio} ||= {}; |
23
|
|
|
|
|
|
|
|
24
|
7
|
|
|
|
|
40
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub to_app { |
28
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
3
|
|
17
|
return sub { $self->call(@_) }; |
|
3
|
|
|
|
|
12
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub call { |
34
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
35
|
3
|
|
|
|
|
6
|
my ($env) = @_; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
5
|
my $response; |
38
|
|
|
|
|
|
|
eval { |
39
|
3
|
|
|
|
|
6
|
my $dispatcher = $self->_build_dispatcher(%{$self->{socketio}}); |
|
3
|
|
|
|
|
32
|
|
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
16
|
$response = $dispatcher->dispatch($env, $self->{handler}); |
42
|
3
|
50
|
|
|
|
7
|
} or do { |
43
|
0
|
|
|
|
|
0
|
my $e = $@; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
require Scalar::Util; |
46
|
0
|
0
|
|
|
|
0
|
die $e unless Scalar::Util::blessed($e); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
my $code = $e->code; |
49
|
0
|
|
0
|
|
|
0
|
my $message = $e->message || 'Internal Server Error'; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my @headers = ( |
52
|
|
|
|
|
|
|
'Content-Type' => 'text/plain', |
53
|
|
|
|
|
|
|
'Content-Length' => length($message), |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
$response = [$code, \@headers, [$message]]; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
22
|
return $response; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub pool { |
63
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
33
|
|
|
25
|
$self->{pool} ||= PocketIO::Pool->new; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
22
|
return $self->{pool}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _build_dispatcher { |
71
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
3
|
|
|
|
|
11
|
return PocketIO::Resource->new(pool => $self->pool, @_); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _get_handler { |
77
|
8
|
|
|
8
|
|
17
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
8
|
100
|
|
|
|
246
|
return $self->{handler} if $self->{handler}; |
80
|
|
|
|
|
|
|
|
81
|
3
|
100
|
100
|
|
|
58
|
die q{Either 'handler', 'class' or 'instance' must be specified} |
82
|
|
|
|
|
|
|
unless $self->{instance} || $self->{class}; |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
50
|
|
|
13
|
my $method = $self->{method} || 'run'; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $instance = $self->{instance} |
87
|
2
|
|
66
|
|
|
12
|
|| do { |
88
|
|
|
|
|
|
|
my $class = $self->{class}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $path = $class; |
91
|
|
|
|
|
|
|
$path =~ s{::}{/}g; |
92
|
|
|
|
|
|
|
$path .= '.pm'; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
require $path; |
95
|
|
|
|
|
|
|
$class->new; |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
17
|
return $instance->$method; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
__END__ |