Trello/WS.pm

filter: Statementstmt 35.7% 25 / 70 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 35.0% 7 / 20 Podpod 10.0% 1 / 10 totaltotal 29.2% 33 / 113 CC 7 SCAR 15.4
CC
7
Cov
31%
connection
12.0
on_frame
12.0
configure
6.0
CRAP 4.7
« Trello/Board.pm ↑ Summary Trello/Common.pm »
1 package Net::Async::Trello::WS;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.005'; # VERSION
7  
8 2 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Net::Async::WebSocket::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 my $json = JSON::MaybeXS->new;
18  
19 sub configure {
20 0 ▶ my ($self, %args) = @_;
Subroutine configure: not called CC=2 SCAR=17.9
Pod documented
21 0 for my $k (grep exists $args{$_}, qw(token trello)) {
22 0 $self->{$k} = delete $args{$k};
23 }
24 0 $self->SUPER::configure(%args);
25 }
26  
27 sub connection {
28 0 ▶ my ($self, %args) = @_;
Subroutine connection: not called CC=3 SCAR=24.8
Pod undocumented
29 0 ▶ $self->{ws_connection} ||= do {
Condition0%0/3
$self->{"ws_connection"} ||= do { my $uri = $self->trello->endpoint("websockets", "token", $self->token); $self->{"ws"}->connect("url", $uri, "host", $uri->host, $uri->scheme eq "wss" ? ("service", 443, "extensions", ["SSL"], "SSL_hostname", $uri->host) : ("service", 80))->then(sub { my($conn) = @_; $Net::Async::Trello::WS::log->tracef("Connected"); "Future"->done($conn); } ) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ws_connection"} ||= do { my $uri = $self->trello->endpoint("websockets", "token", $self->token); $self->{"ws"}->connect("url", $uri, "host", $uri->host, $uri->scheme eq "wss" ? ("service", 443, "extensions", ["SSL"], "SSL_hostname", $uri->host) : ("service", 80))->then(sub { my($conn) = @_; $Net::Async::Trello::WS::log->tracef("Connected"); "Future"->done($conn); } ) }
$self->{"ws_connection"} do { my $uri = $self->trello->endpoint("websockets", "token", $self->token); $self->{"ws"}->connect("url", $uri, "host", $uri->host, $uri->scheme eq "wss" ? ("service", 443, "extensions", ["SSL"], "SSL_hostname", $uri->host) : ("service", 80))->then(sub { my($conn) = @_; $Net::Async::Trello::WS::log->tracef("Connected"); "Future"->done($conn); } ) }
Truth table0%0/3
A ||= B
A= $self->{"ws_connection"}B= do { my $uri = $self->trello->endpoint("websockets", "token", $self->token); $self->{"ws"}->connect("url", $uri, "host", $uri->host, $uri->scheme eq "wss" ? ("service", 443, "extensions", ["SSL"], "SSL_hostname", $uri->host) : ("service", 80))->then(sub { my($conn) = @_; $Net::Async::Trello::WS::log->tracef("Connected"); "Future"->done($conn); } ) }
ABresult
1X1
011
000
30 0 my $uri = $self->trello->endpoint(
31 'websockets',
32 token => $self->token,
33 );
34 $self->{ws}->connect(
35 url => $uri,
36 host => $uri->host,
37 ($uri->scheme eq 'wss'
38 ? (
39 service => 443,
40 extensions => [ qw(SSL) ],
41 SSL_hostname => $uri->host,
42 ) : (
43 service => 80,
44 ))
45 )->then(sub {
46 0 ▶ my ($conn) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 $log->tracef("Connected");
48 # $conn->send_frame($json->encode({"type"=> "ping","reqid"=>0}));
49 0 Future->done($conn);
50 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
$uri->scheme eq 'wss' ? : 0 0 0
51 };
52 }
53  
54 2 my %model_for_type = (
55 board => 'Board',
56 card => 'Card'
57 );
58  
59 sub subscribe {
60 0 ▶ my ($self, $type, $id) = @_;
Subroutine subscribe: not called CC=1 SCAR=6.9
Pod undocumented
61 $self->connection->then(sub {
62 0 ▶ my ($conn) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 $log->tracef("Subscribing to %s %s", $type, $id);
64 $conn->send_frame(
65 buffer => $json->encode({
66 idModel => $id,
67 invitationTokens => [],
68 0 modelType => $model_for_type{$type},
69 reqid => 1,
70 tags => [qw(clientActions updates)],
71 type => "subscribe",
72 }),
73 masked => 1
74 );
75 })
76 0 }
77  
78 sub on_frame {
79 0 ▶ my ($self, $ws, $bytes) = @_;
Subroutine on_frame: not called CC=3 SCAR=24.8
Pod undocumented
80 0 my $text = Encode::decode_utf8($bytes);
81 0 $log->debugf("Have frame [%s]", $text);
82  
83 0 ▶ if(length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) { } 0 0 0
84 0 $log->tracef("<< %s", $text);
85 try {
86 0 my $data = $json->decode($text);
87 0 ▶ if(my $chan = $data->{idModelChannel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chan = $data->{'idModelChannel'}) { } 0 0 0
88 0 $log->tracef("Notification for [%s] - %s", $chan, $data);
89 0 $self->{update_channel}{$chan}->emit($data->{notify});
90 } else {
91 0 $log->warnf("No idea what %s is", $data);
92 }
93 0 } catch {
94 0 $log->errorf("Exception in websocket raw frame handling: %s (original text %s)", $@, $text);
95 }
96 } else {
97 # Empty frame is used for PING, send a response back
98 0 $self->pong;
99 }
100 }
101  
102 sub pong {
103 0 ▶ my ($self) = @_;
Subroutine pong: not called CC=1 SCAR=6.9
Pod undocumented
104 0 $self->{ws}->send_frame('');
105 }
106  
107 sub next_request_id {
108 ++shift->{request_id}
109 0 ▶}
Subroutine next_request_id: not called CC=1 SCAR=6.9
Pod undocumented
110  
111 sub _add_to_loop {
112 0 ▶ my ($self, $loop) = @_;
Subroutine _add_to_loop: not called CC=1 SCAR=6.9
113  
114 $self->add_child(
115 0 $self->{ryu} = Ryu::Async->new
116 );
117  
118 $self->add_child(
119 0 $self->{ws} = Net::Async::WebSocket::Client->new(
120 on_frame => $self->curry::weak::on_frame,
121 )
122 );
123 0 $self->add_child(
124 my $timer = IO::Async::Timer::Periodic->new(
125 interval => 15,
126 on_tick => $self->curry::weak::on_tick,
127 )
128 );
129 0 $timer->start;
130 0 Scalar::Util::weaken($self->{timer} = $timer);
131 }
132  
133 sub on_tick {
134 0 ▶ my ($self) = @_;
Subroutine on_tick: not called CC=2 SCAR=17.9
Pod undocumented
135 0 my $ws = $self->connection;
136 0 ▶ return unless $ws->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $ws->is_ready 0 0 0
137 0 $self->pong;
138 }
139  
140 0 ▶sub trello { shift->{trello} }
Subroutine trello: not called CC=1 SCAR=6.9
Pod undocumented
141 0 ▶sub token { shift->{token} }
Subroutine token: not called CC=1 SCAR=6.9
Pod undocumented
142  
143 0 ▶sub ryu { shift->trello->ryu(@_) }
Subroutine ryu: not called CC=1 SCAR=6.9
Pod undocumented
144  
145 2 1;
146  
« Trello/Board.pm ↑ Summary Trello/Common.pm »