line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::FriendFeed::Realtime; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
31
|
use 5.008_001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
63
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1657
|
use AnyEvent; |
|
1
|
|
|
|
|
6436
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
10269
|
use AnyEvent::HTTP; |
|
1
|
|
|
|
|
41140
|
|
|
1
|
|
|
|
|
113
|
|
9
|
1
|
|
|
1
|
|
1181
|
use Encode; |
|
1
|
|
|
|
|
11925
|
|
|
1
|
|
|
|
|
97
|
|
10
|
1
|
|
|
1
|
|
1122
|
use JSON; |
|
1
|
|
|
|
|
15557
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
1100
|
use MIME::Base64; |
|
1
|
|
|
|
|
673
|
|
|
1
|
|
|
|
|
64
|
|
12
|
1
|
|
|
1
|
|
5
|
use Scalar::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
13
|
1
|
|
|
1
|
|
845
|
use URI; |
|
1
|
|
|
|
|
4649
|
|
|
1
|
|
|
|
|
30
|
|
14
|
1
|
|
|
1
|
|
1791
|
use URI::QueryParam; |
|
1
|
|
|
|
|
806
|
|
|
1
|
|
|
|
|
745
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
0
|
|
|
0
|
0
|
|
my($class, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $headers = {}; |
20
|
0
|
0
|
|
|
|
|
if ($args{username}) { |
21
|
0
|
|
|
|
|
|
my $auth = MIME::Base64::encode( join(":", $args{username}, $args{remote_key}) ); |
22
|
0
|
|
|
|
|
|
$headers->{Authorization} = "Basic $auth"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $uri = URI->new("http://friendfeed-api.com/v2/updates$args{request}"); |
26
|
0
|
|
|
|
|
|
$uri->query_param(updates => 1); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $long_poll; $long_poll = sub { |
31
|
|
|
|
|
|
|
http_get $uri, headers => $headers, on_header => sub { |
32
|
0
|
|
|
|
|
|
my $hdrs = shift; |
33
|
0
|
0
|
|
|
|
|
if ($hdrs->{Status} ne '200') { |
34
|
0
|
|
0
|
|
|
|
($args{on_error} || sub { die @_ })->("$uri: $hdrs->{Status} $hdrs->{Reason}"); |
35
|
0
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
return 1; |
38
|
|
|
|
|
|
|
}, sub { |
39
|
0
|
|
|
|
|
|
my($body, $headers) = @_; |
40
|
0
|
0
|
|
|
|
|
return $long_poll->() unless $body; |
41
|
0
|
|
0
|
|
|
|
my $res = eval { JSON::decode_json($body) } || do { |
42
|
|
|
|
|
|
|
($args{on_error} || sub { die @_ })->("JSON parsing error: $@"); |
43
|
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($res->{errorCode}) { |
47
|
0
|
|
0
|
|
|
|
($args{on_error} || sub { die @_ })->($res->{errorCode}); |
48
|
0
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
for my $entry (@{$res->{entries}}) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
0
|
|
|
|
($args{on_entry} || sub {})->($entry); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ($res->{realtime}) { |
56
|
0
|
|
|
|
|
|
$uri = $uri->clone; |
57
|
0
|
|
|
|
|
|
$uri->query_param(cursor => $res->{realtime}{cursor}); |
58
|
0
|
|
|
|
|
|
$long_poll->(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
0
|
|
|
}; |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
0
|
|
|
$self->{guard} = AnyEvent::Util::guard { undef $long_poll }; |
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$long_poll->(); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |