| 1 | package Marathon::Events; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use AnyEvent::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use IO::All '-tie'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 7 | 0 | my ( $class, $parent ) = @_; | |||||||||
| 8 | 0 | return bless { callbacks => [], parent => $parent }; | |||||||||
| 9 | } | ||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub register { | ||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 12 | 0 | my ($self, $callback) = @_; | |||||||||
| 13 | 0 | push @{$self->callbacks}, $callback; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub callbacks { | ||||||||
|
Subroutine
callbacks: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 17 | 0 | my ($self) = @_; | |||||||||
| 18 | 0 | ▶ | return wantarray ? @{$self->{callbacks}} : $self->{callbacks}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub start { | ||||||||
|
Subroutine
start: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 22 | 0 | my $self = shift; | |||||||||
| 23 | 0 | my $cv = AnyEvent->condvar; | |||||||||
| 24 | 0 | $self->{parent}->{_url} =~ m,https?\://([^/]+),; | |||||||||
| 25 | 0 | my $addr = $1; | |||||||||
| 26 | |||||||||||
| 27 | 0 | my $io = io($addr); | |||||||||
| 28 | 0 | $io->print("GET /v2/events HTTP/1.1\nAccept: text/event-stream\nHost: $addr\n\n"); | |||||||||
| 29 | 0 | ▶ | while (<$io>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | ▶ | last if /^\s*$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | } | ||||||||||
| 32 | 0 | ▶ | my $watcher = AE::io $io->io_handle, 0, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 33 | 0 | my $text = <$io>; | |||||||||
| 34 | 0 | foreach ( $self->callbacks ) { | |||||||||
| 35 | 0 | $_->($text); | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | }; | |||||||||
| 38 | 0 | print STDERR "yield\n"; | |||||||||
| 39 | 0 | return $io; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 4 | 1; | |||||||||