line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Marathon::Events; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
3073
|
use AnyEvent::Handle; |
|
4
|
|
|
|
|
98179
|
|
|
4
|
|
|
|
|
191
|
|
4
|
4
|
|
|
4
|
|
2645
|
use IO::All '-tie'; |
|
4
|
|
|
|
|
43409
|
|
|
4
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
0
|
|
|
0
|
0
|
|
my ( $class, $parent ) = @_; |
8
|
0
|
|
|
|
|
|
return bless { callbacks => [], parent => $parent }; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
0
|
|
|
0
|
0
|
|
my ($self, $callback) = @_; |
13
|
0
|
|
|
|
|
|
push @{$self->callbacks}, $callback; |
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub callbacks { |
17
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
18
|
0
|
0
|
|
|
|
|
return wantarray ? @{$self->{callbacks}} : $self->{callbacks}; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub start { |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $cv) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my ($addr) = $self->{parent}{_url} =~ m{ https?://([^/]+) }x; |
25
|
0
|
|
|
|
|
|
my $addr_port = $addr; |
26
|
0
|
0
|
|
|
|
|
if ($addr !~ /:/) { |
27
|
0
|
0
|
|
|
|
|
if ($marathon_url =~ /^https/) { |
28
|
0
|
|
|
|
|
|
$addr_port .= '443'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { # =~ /^http/ |
31
|
0
|
|
|
|
|
|
$addr_port .= ':80'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $io = io($addr_port); |
36
|
0
|
|
|
|
|
|
$io->print("GET /v2/events HTTP/1.1\nAccept: text/event-stream\nHost: $addr\n\n"); |
37
|
0
|
|
|
|
|
|
while (<$io>) { |
38
|
0
|
0
|
|
|
|
|
last if /^\s*$/; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
my $watcher = AE::io $io->io_handle, 0, sub { |
41
|
0
|
|
|
0
|
|
|
my $text = <$io>; |
42
|
0
|
|
|
|
|
|
foreach ( $self->callbacks ) { |
43
|
0
|
|
|
|
|
|
$_->($text); |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
}; |
46
|
0
|
|
|
|
|
|
return $watcher; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |