Slack/Socket.pm

filter: Statementstmt 81.5% 354 / 434 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 86.5% 116 / 134 Podpod 26.6% 4 / 15 totaltotal 73.8% 474 / 642 CC 24 SCAR 17.9
CC
24
Cov
74%
link_shared
56.0
on_frame
42.0
configure
12.0
CRAP 6.0
« Slack.pm ↑ Summary Slack/Commands.pm »
1 package Net::Async::Slack::Socket;
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.007'; # VERSION
7 2 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8  
9 2 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Net::Async::Slack::Socket - socket-mode notifications for L<https://slack.com>
14  
15 =head1 DESCRIPTION
16  
17 This is a basic wrapper for Slack's socket-mode features.
18  
19 This provides an event stream using websockets.
20  
21 For a full list of events, see L<https://api.slack.com/events>.
22  
23 =cut
24  
25 2 ▶no indirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use mro;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use Dir::Self;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use URI::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 2 ▶use IO::Async::Timer::Countdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use Net::Async::WebSocket::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 2 ▶use Net::Async::Slack::Event::AccountsChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use Net::Async::Slack::Event::AppHomeOpened;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use Net::Async::Slack::Event::AppMention;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 ▶use Net::Async::Slack::Event::AppRateLimited;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶use Net::Async::Slack::Event::AppUninstalled;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 ▶use Net::Async::Slack::Event::BlockActions;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 ▶use Net::Async::Slack::Event::BotAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use Net::Async::Slack::Event::BotChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 ▶use Net::Async::Slack::Event::Bot;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 ▶use Net::Async::Slack::Event::ChannelArchive;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 ▶use Net::Async::Slack::Event::ChannelCreated;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 ▶use Net::Async::Slack::Event::ChannelDeleted;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 2 ▶use Net::Async::Slack::Event::ChannelHistoryChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2 ▶use Net::Async::Slack::Event::ChannelJoined;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 2 ▶use Net::Async::Slack::Event::ChannelLeft;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 2 ▶use Net::Async::Slack::Event::ChannelMarked;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶use Net::Async::Slack::Event::Channel;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 ▶use Net::Async::Slack::Event::ChannelRename;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 2 ▶use Net::Async::Slack::Event::ChannelUnarchive;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 ▶use Net::Async::Slack::Event::CommandsChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 ▶use Net::Async::Slack::Event::DndUpdated;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 2 ▶use Net::Async::Slack::Event::DndUpdatedUser;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 2 ▶use Net::Async::Slack::Event::EmailDomainChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 2 ▶use Net::Async::Slack::Event::EmojiChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 2 ▶use Net::Async::Slack::Event::FileChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 2 ▶use Net::Async::Slack::Event::FileCommentAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 2 ▶use Net::Async::Slack::Event::FileCommentDeleted;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 2 ▶use Net::Async::Slack::Event::FileCommentEdited;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 2 ▶use Net::Async::Slack::Event::FileCreated;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 2 ▶use Net::Async::Slack::Event::FileDeleted;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 2 ▶use Net::Async::Slack::Event::FilePublic;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 2 ▶use Net::Async::Slack::Event::FileShared;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 2 ▶use Net::Async::Slack::Event::FileUnshared;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 2 ▶use Net::Async::Slack::Event::Goodbye;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 2 ▶use Net::Async::Slack::Event::GridMigrationFinished;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 2 ▶use Net::Async::Slack::Event::GridMigrationStarted;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 ▶use Net::Async::Slack::Event::GroupArchive;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 2 ▶use Net::Async::Slack::Event::GroupClose;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 2 ▶use Net::Async::Slack::Event::GroupDeleted;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 2 ▶use Net::Async::Slack::Event::GroupHistoryChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 2 ▶use Net::Async::Slack::Event::GroupJoined;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 2 ▶use Net::Async::Slack::Event::GroupLeft;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 2 ▶use Net::Async::Slack::Event::GroupMarked;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use Net::Async::Slack::Event::GroupOpen;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶use Net::Async::Slack::Event::GroupRename;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 2 ▶use Net::Async::Slack::Event::GroupUnarchive;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶use Net::Async::Slack::Event::Hello;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 2 ▶use Net::Async::Slack::Event::ImClose;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 2 ▶use Net::Async::Slack::Event::ImCreated;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 2 ▶use Net::Async::Slack::Event::ImHistoryChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
91 2 ▶use Net::Async::Slack::Event::ImMarked;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 2 ▶use Net::Async::Slack::Event::ImOpen;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 2 ▶use Net::Async::Slack::Event::LinkShared;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 2 ▶use Net::Async::Slack::Event::ManualPresenceChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 2 ▶use Net::Async::Slack::Event::MemberJoinedChannel;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 2 ▶use Net::Async::Slack::Event::MemberLeftChannel;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 2 ▶use Net::Async::Slack::Event::MessageAction;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 2 ▶use Net::Async::Slack::Event::MessageAppHome;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 2 ▶use Net::Async::Slack::Event::MessageChannels;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 2 ▶use Net::Async::Slack::Event::MessageGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 2 ▶use Net::Async::Slack::Event::MessageIm;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 2 ▶use Net::Async::Slack::Event::MessageMpim;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 2 ▶use Net::Async::Slack::Event::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 2 ▶use Net::Async::Slack::Event::PinAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 2 ▶use Net::Async::Slack::Event::PinRemoved;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 2 ▶use Net::Async::Slack::Event::PrefChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 2 ▶use Net::Async::Slack::Event::PresenceChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 2 ▶use Net::Async::Slack::Event::PresenceQuery;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 2 ▶use Net::Async::Slack::Event::PresenceSub;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 2 ▶use Net::Async::Slack::Event::ReactionAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 2 ▶use Net::Async::Slack::Event::ReactionRemoved;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 2 ▶use Net::Async::Slack::Event::ReconnectURL;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 2 ▶use Net::Async::Slack::Event::ResourcesAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 2 ▶use Net::Async::Slack::Event::ResourcesRemoved;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 2 ▶use Net::Async::Slack::Event::ScopeDenied;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 2 ▶use Net::Async::Slack::Event::ScopeGranted;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 2 ▶use Net::Async::Slack::Event::StarAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 2 ▶use Net::Async::Slack::Event::StarRemoved;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 2 ▶use Net::Async::Slack::Event::SubteamCreated;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 2 ▶use Net::Async::Slack::Event::SubteamMembersChanged;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 2 ▶use Net::Async::Slack::Event::SubteamSelfAdded;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 2 ▶use Net::Async::Slack::Event::SubteamSelfRemoved;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 2 ▶use Net::Async::Slack::Event::SubteamUpdated;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 2 ▶use Net::Async::Slack::Event::TeamDomainChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 2 ▶use Net::Async::Slack::Event::TeamJoin;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 2 ▶use Net::Async::Slack::Event::TeamMigrationStarted;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 2 ▶use Net::Async::Slack::Event::TeamPlanChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 2 ▶use Net::Async::Slack::Event::TeamPrefChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 2 ▶use Net::Async::Slack::Event::TeamProfileChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 2 ▶use Net::Async::Slack::Event::TeamProfileDelete;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 2 ▶use Net::Async::Slack::Event::TeamProfileReorder;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 2 ▶use Net::Async::Slack::Event::TeamRename;
Subroutine BEGIN: called CC=1 SCAR=0.0
133 2 ▶use Net::Async::Slack::Event::TokensRevoked;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 2 ▶use Net::Async::Slack::Event::URLVerification;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 2 ▶use Net::Async::Slack::Event::UserChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 2 ▶use Net::Async::Slack::Event::UserResourceDenied;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 2 ▶use Net::Async::Slack::Event::UserResourceGranted;
Subroutine BEGIN: called CC=1 SCAR=0.0
138 2 ▶use Net::Async::Slack::Event::UserResourceRemoved;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 2 ▶use Net::Async::Slack::Event::UserTyping;
Subroutine BEGIN: called CC=1 SCAR=0.0
140  
141 2 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
142  
143 2 my $json = JSON::MaybeXS->new;
144  
145 =head1 METHODS
146  
147 =head2 events
148  
149 This is the stream of events, as a L<Ryu::Source>.
150  
151 Example usage:
152  
153 $rtm->events
154 ->filter(type => 'message')
155 ->sprintf_methods('> %s', $_->text)
156 ->say
157 ->await;
158  
159 =cut
160  
161 sub events {
162 0 ▶ my ($self) = @_;
Subroutine events: not called CC=2 SCAR=17.9
Pod documented
163 0 ▶ $self->{events} //= do {
Condition0%0/3
$self->{"events"} //= do { $self->ryu->source }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"events"} //= do { $self->ryu->source }
$self->{"events"} do { $self->ryu->source }
Truth table0%0/3
A //= B
A= $self->{"events"}B= do { $self->ryu->source }
ABresult
1X1
011
000
164 0 $self->ryu->source
165 }
166 }
167  
168 =head1 METHODS - Internal
169  
170 You may not need to call these directly. If I'm wrong and you find yourself having
171 to do that, please complain via the usual channels.
172  
173 =head2 connect
174  
175 Establishes the connection. Called by the top-level L<Net::Async::Slack> instance.
176  
177 =cut
178  
179 0 ▶async sub connect {
Subroutine connect: not called CC=2 SCAR=17.9
Pod documented
180 0 my ($self, %args) = @_;
181 0 ▶ my $uri = $self->wss_uri or die 'no websocket URI available';
Branch: 1 branch
BranchTrueFalseTotal
my $uri = $self->wss_uri or die "no websocket URI available" 0 0 0
182 $self->add_child(
183 0 $self->{ws} = Net::Async::WebSocket::Client->new(
184 on_frame => $self->curry::weak::on_frame,
185 on_ping_frame => $self->curry::weak::on_ping_frame,
186 )
187 );
188 0 $log->tracef('URL for websockets will be %s', "$uri");
189 my $res = await $self->{ws}->connect(
190 0 url => "$uri",
191 );
192 0 $self->event_mangler;
193 0 return $res;
194 2 }
195  
196 sub on_ping_frame {
197 0 ▶ my ($self, $ws, $bytes) = @_;
Subroutine on_ping_frame: not called CC=1 SCAR=6.9
Pod undocumented
198 0 $ws->send_pong_frame('');
199 }
200  
201 sub on_frame {
202 0 ▶ my ($self, $ws, $bytes) = @_;
Subroutine on_frame: not called CC=6 SCAR=37.4
Pod undocumented
203 0 my $text = Encode::decode_utf8($bytes);
204  
205 # Empty frame is used for PING, send a response back
206 0 ▶ if(!length($text)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $text) { } 0 0 0
207 0 $ws->send_frame('');
208 } else {
209 0 $log->tracef("<< %s", $text);
210 try {
211 0 my $data = $json->decode($text);
212 0 ▶ if(my $env_id = $data->{envelope_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $env_id = $data->{"envelope_id"}) 0 0 0
213 0 $self->ws->send_frame(
214 buffer => $json->encode({
215 envelope_id => $env_id
216 }),
217 masked => 1
218 )->retain;
219 }
220 0 ▶ if(my $type = $data->{payload}{type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $data->{"payload"}{"type"}) 0 0 0
221 0 ▶ if($type eq 'event_callback') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'event_callback') { } 0 0 0
222 my $ev = Net::Async::Slack::EventType->from_json(
223 $data->{payload}{event}
224 0 );
225 0 $log->tracef("Have event [%s], emitting", $ev->type);
226 0 $self->events->emit($ev);
227 } else {
228 0 ▶ if(my $ev = Net::Async::Slack::EventType->from_json(
Branch: 1 branch
BranchTrueFalseTotal
if (my $ev = 'Net::Async::Slack::EventType'->from_json($data->{'payload'})) { } 0 0 0
229 $data->{payload}
230 )) {
231 0 $log->tracef("Have event [%s], emitting", $ev->type);
232 0 $self->events->emit($ev);
233 } else {
234 0 $log->errorf('Failed to locate event type from payload %s', $data->{payload});
235 }
236 }
237 }
238 0 } catch {
239 0 $log->errorf("Exception in websocket raw frame handling: %s (original text %s)", $@, $text);
240 }
241 }
242 }
243  
244 0 ▶sub slack { shift->{slack} }
Subroutine slack: not called CC=1 SCAR=6.9
Pod undocumented
245  
246 0 ▶sub wss_uri { shift->{wss_uri} }
Subroutine wss_uri: not called CC=1 SCAR=6.9
Pod undocumented
247  
248 0 ▶sub ws { shift->{ws} }
Subroutine ws: not called CC=1 SCAR=6.9
Pod undocumented
249  
250 0 ▶sub ryu { shift->{ryu} }
Subroutine ryu: not called CC=1 SCAR=6.9
Pod undocumented
251  
252 sub next_id {
253 0 ▶ my ($self, $id) = @_;
Subroutine next_id: not called CC=2 SCAR=17.9
Pod undocumented
254 0 ▶ $self->{last_id} = $id // ++$self->{last_id};
Condition0%0/3
$id // ++$self->{"last_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$id // ++$self->{"last_id"}
$id ++$self->{"last_id"}
Truth table0%0/3
A // B
A= $idB= ++$self->{"last_id"}
ABresult
1X1
011
000
255 }
256  
257 sub configure {
258 0 ▶ my ($self, %args) = @_;
Subroutine configure: not called CC=3 SCAR=24.8
Pod documented
259 0 for my $k (qw(slack wss_uri)) {
260 0 ▶ $self->{$k} = delete $args{$k} if exists $args{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$k} 0 0 0
261 }
262 0 $self->next::method(%args);
263 }
264  
265 sub ping_timer {
266 0 ▶ my ($self) = @_;
Subroutine ping_timer: not called CC=2 SCAR=17.9
Pod undocumented
267 0 ▶ $self->{ping_timer} ||= do {
Condition0%0/3
$self->{"ping_timer"} ||= do { $self->add_child(my $timer = "IO::Async::Timer::Countdown"->new("delay", 10, "on_expire", $self->$curry::weak(sub { (shift())->trigger_ping; } ))); $timer }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ping_timer"} ||= do { $self->add_child(my $timer = "IO::Async::Timer::Countdown"->new("delay", 10, "on_expire", $self->$curry::weak(sub { (shift())->trigger_ping; } ))); $timer }
$self->{"ping_timer"} do { $self->add_child(my $timer = "IO::Async::Timer::Countdown"->new("delay", 10, "on_expire", $self->$curry::weak(sub { (shift())->trigger_ping; } ))); $timer }
Truth table0%0/3
A ||= B
A= $self->{"ping_timer"}B= do { $self->add_child(my $timer = "IO::Async::Timer::Countdown"->new("delay", 10, "on_expire", $self->$curry::weak(sub { (shift())->trigger_ping; } ))); $timer }
ABresult
1X1
011
000
268 $self->add_child(
269 my $timer = IO::Async::Timer::Countdown->new(
270 delay => 10,
271 0 ▶ on_expire => $self->$curry::weak(sub { shift->trigger_ping }),
Subroutine __ANON__: not called CC=1 SCAR=6.9
272 )
273 );
274 0 $timer
275 }
276 }
277  
278 =head2 handle_unfurl_domain
279  
280 =cut
281  
282 sub handle_unfurl_domain {
283 0 ▶ my ($self, %args) = @_;
Subroutine handle_unfurl_domain: not called CC=3 SCAR=24.8
Pod documented
284 $self->{unfurl_domain}{
285 delete $args{domain} || die 'need a domain'
286 } = $args{handler}
287 0 ▶ or die 'need a handler';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"unfurl_domain"}{delete $args{"domain"} or die "need a domain"} = $args{"handler"} or die "need a handler" 0 0 0
Condition0%0/2
delete $args{'domain'} || die('need a domain')
l!l
00
MC/DC0%0/1
delete $args{'domain'} || die('need a domain')
delete $args{'domain'}
Truth table0%0/2
A
A= delete $args{'domain'}
Aresult
11
00
288 0 return;
289 }
290  
291 sub event_mangler {
292 0 ▶ my ($self) = @_;
Subroutine event_mangler: not called CC=2 SCAR=17.9
Pod undocumented
293 0 ▶ $self->{event_handling} //= $self->events->map($self->$curry::weak(async sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
294 0 my ($self, $ev) = @_;
295 try {
296 0 ▶ if(my $code = $self->can($ev->type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->can($ev->type)) { } 0 0 0
297 0 await $self->$code($ev);
298 } else {
299 0 $log->tracef('Ignoring event %s', $ev->type);
300 }
301 0 } catch ($e) {
302 0 $log->errorf('Event handling on %s failed: %s', $ev, $e);
303 }
304 0 ▶ }))->ordered_futures(
Condition0%0/3
$self->{"event_handling"} //= $self->events->map($self->$curry::weak(sub { XXX; eval { do { my($self, $ev) = @_; do { XXX } } }; XXX; } ))->ordered_futures("low", 16, "high", 100)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"event_handling"} //= $self->events->map($self->$curry::weak(sub { XXX; eval { do { my($self, $ev) = @_; do { XXX } } }; XXX; } ))->ordered_futures("low", 16, "high", 100)
$self->{"event_handling"} $self->events->map($self->$curry::weak(sub { XXX; eval { do { my($self, $ev) = @_; do { XXX } } }; XXX; } ))->ordered_futures("low", 16, "high", 100)
Truth table0%0/3
A //= B
A= $self->{"event_handling"}B= $self->events->map($self->$curry::weak(sub { XXX; eval { do { my($self, $ev) = @_; do { XXX } } }; XXX; } ))->ordered_futures("low", 16, "high", 100)
ABresult
1X1
011
000
305 low => 16,
306 high => 100,
307 );
308 }
309  
310 0 ▶async sub link_shared {
Subroutine link_shared: not called CC=7 SCAR=40.3
Pod undocumented
311 0 my ($self, $ev) = @_;
312 0 my %uri_map;
313 0 for my $link ($ev->{links}->@*) {
314 0 ▶ if(my $handler = $self->{unfurl_domain}{$link->{domain}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $self->{"unfurl_domain"}{$link->{"domain"}}) 0 0 0
315 0 my $uri = URI->new($link->{url});
316 0 $log->tracef('Unfurling URL %s', $uri);
317 0 my $unfurled = await $handler->($uri);
318 0 ▶ $uri_map{$uri} = $unfurled if $unfurled;
Branch: 1 branch
BranchTrueFalseTotal
if $unfurled 0 0 0
319 }
320 }
321 0 ▶ return unless keys %uri_map;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %uri_map 0 0 0
322 my $res = await $self->slack->chat_unfurl(
323 channel => $ev->{channel_id} // $ev->{channel}->id,
324 ts => $ev->{message_ts},
325 0 ▶ unfurls => \%uri_map,
Condition0%0/3
$ev->{"channel_id"} // $ev->{"channel"}->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$ev->{"channel_id"} // $ev->{"channel"}->id
$ev->{"channel_id"} $ev->{"channel"}->id
Truth table0%0/3
A // B
A= $ev->{"channel_id"}B= $ev->{"channel"}->id
ABresult
1X1
011
000
326 );
327 0 ▶ die 'invalid URI unfurling' unless $res->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"ok"} 0 0 0
328 0 return;
329 2 }
330  
331 sub trigger_ping {
332 0 ▶ my ($self, %args) = @_;
Subroutine trigger_ping: not called CC=2 SCAR=17.9
Pod undocumented
333 0 my $id = $self->next_id($args{id});
334 0 $self->ws->send_frame(
335 buffer => $json->encode({
336 type => 'ping',
337 id => $id,
338 }),
339 masked => 1
340 );
341 0 $self->ping_timer->reset;
342 0 ▶ $self->ping_timer->start if $self->ping_timer->is_expired;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ping_timer->is_expired 0 0 0
343 }
344  
345 sub _add_to_loop {
346 0 ▶ my ($self, $loop) = @_;
Subroutine _add_to_loop: not called CC=2 SCAR=17.9
347 $self->add_child(
348 0 $self->{ryu} = Ryu::Async->new
349 );
350 # $self->ping_timer->start;
351 0 ▶ $self->{last_id} //= 0;
Condition0%0/2
$self->{"last_id"} //= 0
l!l
00
MC/DC0%0/1
$self->{"last_id"} //= 0
$self->{"last_id"}
Truth table0%0/2
A
A= $self->{"last_id"}
Aresult
11
00
352 }
353  
354 2 1;
355  
356 =head1 AUTHOR
357  
358 Tom Molesworth <TEAM@cpan.org>
359  
360 =head1 LICENSE
361  
362 Copyright Tom Molesworth 2016-2021. Licensed under the same terms as Perl itself.
363  
« Slack.pm ↑ Summary Slack/Commands.pm »