line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PocketIO::Client::IO; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
268931
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
63
|
|
5
|
1
|
|
|
1
|
|
588
|
use AnyEvent::PocketIO::Client; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
6
|
use Scalar::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
275
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub connect { |
11
|
1
|
|
|
1
|
1
|
81010
|
my ( $clsas, $url ) = @_; |
12
|
1
|
|
|
|
|
60
|
my $client = AnyEvent::PocketIO::Client->new; |
13
|
1
|
|
|
|
|
28
|
my ( $server, $port ) = $url =~ m{https?://([.\w]+)(?::(\d+))?}; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
50
|
|
|
12
|
$port ||= 80; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
6
|
my $socket; |
18
|
1
|
|
|
|
|
45
|
my $cv = AnyEvent->condvar; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$client->handshake( $server, $port, sub { |
21
|
1
|
|
|
1
|
|
4
|
my ( $error, $self, $sesid, $hbtimeout, $contimeout, $transports ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
6
|
if ( $error ) { |
24
|
0
|
|
|
|
|
0
|
Carp::carp( $error->{ message } ); |
25
|
0
|
|
|
|
|
0
|
$cv->send; |
26
|
0
|
|
|
|
|
0
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->on('open' => sub { |
30
|
1
|
|
|
|
|
4
|
$cv->send; |
31
|
1
|
|
|
|
|
19
|
}); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
13
|
$self->open(); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
658
|
return; |
36
|
1
|
|
|
|
|
7618
|
} ); |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
777
|
$cv->wait; |
39
|
|
|
|
|
|
|
|
40
|
1
|
50
|
|
|
|
84
|
return unless $client->conn; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
4
|
$socket = $client->conn->socket; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
15
|
bless $socket, 'PocketIO::Socket::ForClient'; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
8
|
$socket->{ _client } = $client; |
47
|
1
|
|
|
|
|
6
|
Scalar::Util::weaken( $socket->{ _client } ); |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
5
|
return $socket; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package PocketIO::Socket::ForClient; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
|
4
|
use base 'PocketIO::Socket'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
194
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub on { |
58
|
3
|
|
|
3
|
|
3347
|
my $self = shift; |
59
|
3
|
|
|
|
|
11
|
my ( $name, $cb ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
3
|
100
|
66
|
|
|
21
|
if ( $name eq 'connect' and $cb ) { |
62
|
1
|
|
|
|
|
4
|
my $w; $w = AnyEvent->timer( after => 0, interval => 1, cb => sub { |
63
|
2
|
100
|
|
2
|
|
994103
|
if ( $self->{ _client }->is_opened ) { |
64
|
1
|
|
|
|
|
10
|
undef $w; |
65
|
1
|
|
|
|
|
10
|
$cb->( $self ); |
66
|
|
|
|
|
|
|
} |
67
|
1
|
|
|
|
|
16
|
} ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else { |
70
|
2
|
|
|
|
|
21
|
$self->SUPER::on( @_ ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
PocketIO::Client::IO - simple pocketio client |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
use PocketIO::Client::IO; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $socket = PocketIO::Client::IO->connect("http://localhost:3000/"); |
88
|
|
|
|
|
|
|
# $socket is a PocketIO::Socket object. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $cv = AnyEvent->condvar; |
91
|
|
|
|
|
|
|
my $w = AnyEvent->timer( after => 5, cb => $cv ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$socket->on( 'message', sub { |
94
|
|
|
|
|
|
|
say $_[1]; |
95
|
|
|
|
|
|
|
} ); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$socket->on( 'connect', sub { |
98
|
|
|
|
|
|
|
$socket->send('Parumon!'); |
99
|
|
|
|
|
|
|
$socket->emit('hello', "perl"); |
100
|
|
|
|
|
|
|
} ); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$cv->wait; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Simple Socket.IO client using AnyEvent::PocketIO::Client. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This is B version. APIs will be changed. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Currently acceptable transport id is B only. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
If you want to controll client action more detail, |
113
|
|
|
|
|
|
|
please see to L. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 METHODS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 connect |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$socket = PocketIO::Client::IO->connect( $url ); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Handshakes and connects to C<$url>, then returns a C |
122
|
|
|
|
|
|
|
object which inherits L. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L, L, L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 AUTHOR |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Makamaka Hannyaharamitu, Emakamaka[at]cpan.orgE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Copyright 2012 by Makamaka Hannyaharamitu |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
137
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|