File Coverage

blib/lib/Minion/Notifier/Transport/WebSocket.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package Minion::Notifier::Transport::WebSocket;
2              
3 1     1   5 use Mojo::Base 'Minion::Notifier::Transport';
  1         3  
  1         7  
4              
5 1     1   164 use Mojo::URL;
  1         1  
  1         9  
6 1     1   36 use Mojo::UserAgent;
  1         2  
  1         10  
7              
8             has ua => sub { Mojo::UserAgent->new };
9             has url => sub { die 'url is required' };
10              
11             sub listen {
12 1     1 0 5 my $self = shift;
13             $self->ua->websocket($self->url => sub {
14 1     1   7443 my ($ua, $tx) = @_;
15             $tx->on(json => sub {
16 3         7499 my ($tx, $data) = @_;
17 3         23 $self->emit(notified => @$data);
18 1         13 });
19 1         3 });
20             }
21              
22             sub send {
23 3     3 0 45 my ($self, $id, $message) = @_;
24             $self->ua->websocket($self->url => sub {
25 3     3   64404 my ($ua, $tx) = @_;
26 3         24 $tx->send({json => [$id, $message]}); #TODO finish after send?
27 3         16 });
28             }
29              
30              
31             1;
32