Async/Server.pm

filter: Statementstmt 45.8% 39 / 85 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 23.2% 13 / 56 Podpod 100% 43 / 43 totaltotal 51.5% 101 / 196 CC 9 SCAR 8.1
CC
9
Cov
46%
__ANON__
6.0
__ANON__
6.0
_submit
3.8
CRAP 2.2
« Async/Transport.pm ↑ Summary Async.pm »
1 package LibTmux::Async::Server;
2 1 ▶use v5.44;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use LibTmux::Async;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use LibTmux::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use LibTmux::Async::Transport;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use LibTmux::Async::X;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub new ($class, %args) {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
9 1 my %async;
10 1 for my $key (qw(loop max_concurrent max_queue)) {
11 3 ▶ $async{$key} = delete $args{$key} if exists $args{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$key} 1 2 3
12 }
13 1 my $transport = LibTmux::Async::Transport->new(%async);
14 return bless {
15 core => LibTmux::Server->new(%args),
16 transport => $transport,
17 loop => $async{loop},
18 1 operations => {},
19 next_id => 0,
20 closing => false
21 }, $class;
22 }
23  
24 3 ▶sub _submit ($self, $name, %args) {
Subroutine _submit: called CC=3 SCAR=13.2
25 3 my $future = $self->{loop}->new_future;
26 return $future->fail(
27 LibTmux::Async::X::Closed->new(message => 'async server is closing'))
28 3 ▶ if $self->{closing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closing"} 1 2 3
29 2 my $operation;
30 2 try {
31 $operation =
32 $name eq 'attach_argv'
33 ? LibTmux::Operation->value($self->{core}->attach_argv(%args))
34 2 ▶ : $self->{core}->operation($name, %args);
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'attach_argv' ? : 0 2 2
35 }
36 1 catch ($error) { return $future->fail($error) }
37 1 my $id = ++$self->{next_id};
38 1 $self->{operations}{$id} = $future;
39 1 ▶ $future->on_ready(sub { delete $self->{operations}{$id} });
Subroutine __ANON__: called CC=1 SCAR=0.0
40 my $cancel = $operation->run(
41 0 ▶ sub ($request, $done, $fail) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 my $request_future = $self->{transport}->execute(%$request);
43 0 ▶ $request_future->on_done(sub ($result) { $done->($result) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 ▶ $request_future->on_fail(sub ($error) { $fail->($error) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 return
46 0 ▶ sub { $request_future->cancel unless $request_future->is_ready };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $request_future->is_ready 0 0 0
47 },
48 1 ▶ sub ($value) { $future->done($value) unless $future->is_ready },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 1 0 1
49 0 ▶ sub ($error) { $future->fail($error) unless $future->is_ready }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $future->is_ready 0 0 0
50 1 );
51 1 $future->on_cancel($cancel);
52 1 return $future;
53 }
54  
55 1 ▶sub close ($self) {
Subroutine close: called CC=2 SCAR=6.9
Pod documented
56 1 $self->{closing} = true;
57 1 $_->cancel for values $self->{operations}->%*;
58 1 return $self->{transport}->close;
59 }
60 0 ▶sub cmd ($self, @argv) { $self->_submit('cmd', argv => \@argv) }
Subroutine cmd: not called CC=1 SCAR=6.9
Pod documented
61 0 ▶sub listings ($self, $kind) { $self->_submit('listings', kind => $kind) }
Subroutine listings: not called CC=1 SCAR=6.9
Pod documented
62 0 ▶sub batch ($self, $requests) { $self->_submit('batch', requests => $requests) }
Subroutine batch: not called CC=1 SCAR=6.9
Pod documented
63 0 ▶sub execute ($self, %args) { $self->_submit('execute', %args) }
Subroutine execute: not called CC=1 SCAR=6.9
Pod documented
64 1 ▶sub new_session ($self, %args) { $self->_submit('new_session', %args) }
Subroutine new_session: called CC=1 SCAR=0.0
Pod documented
65 0 ▶sub new_window ($self, %args) { $self->_submit('new_window', %args) }
Subroutine new_window: not called CC=1 SCAR=6.9
Pod documented
66 0 ▶sub split_pane ($self, %args) { $self->_submit('split_pane', %args) }
Subroutine split_pane: not called CC=1 SCAR=6.9
Pod documented
67 1 ▶sub snapshot ($self, %args) { $self->_submit('snapshot', %args) }
Subroutine snapshot: called CC=1 SCAR=0.0
Pod documented
68 0 ▶sub query_panes ($self, %args) { $self->_submit('query_panes', %args) }
Subroutine query_panes: not called CC=1 SCAR=6.9
Pod documented
69 1 ▶sub explain_panes ($self, %args) { $self->_submit('explain_panes', %args) }
Subroutine explain_panes: called CC=1 SCAR=0.0
Pod documented
70 0 ▶sub rename_session ($self, %args) { $self->_submit('rename_session', %args) }
Subroutine rename_session: not called CC=1 SCAR=6.9
Pod documented
71 0 ▶sub rename_window ($self, %args) { $self->_submit('rename_window', %args) }
Subroutine rename_window: not called CC=1 SCAR=6.9
Pod documented
72 0 ▶sub link_window ($self, %args) { $self->_submit('link_window', %args) }
Subroutine link_window: not called CC=1 SCAR=6.9
Pod documented
73 0 ▶sub unlink_window ($self, %args) { $self->_submit('unlink_window', %args) }
Subroutine unlink_window: not called CC=1 SCAR=6.9
Pod documented
74 0 ▶sub move_window ($self, %args) { $self->_submit('move_window', %args) }
Subroutine move_window: not called CC=1 SCAR=6.9
Pod documented
75 0 ▶sub select_window ($self, %args) { $self->_submit('select_window', %args) }
Subroutine select_window: not called CC=1 SCAR=6.9
Pod documented
76 0 ▶sub select_pane ($self, %args) { $self->_submit('select_pane', %args) }
Subroutine select_pane: not called CC=1 SCAR=6.9
Pod documented
77 0 ▶sub select_layout ($self, %args) { $self->_submit('select_layout', %args) }
Subroutine select_layout: not called CC=1 SCAR=6.9
Pod documented
78 0 ▶sub resize_pane ($self, %args) { $self->_submit('resize_pane', %args) }
Subroutine resize_pane: not called CC=1 SCAR=6.9
Pod documented
79 0 ▶sub set_title ($self, %args) { $self->_submit('set_title', %args) }
Subroutine set_title: not called CC=1 SCAR=6.9
Pod documented
80 0 ▶sub send_keys ($self, %args) { $self->_submit('send_keys', %args) }
Subroutine send_keys: not called CC=1 SCAR=6.9
Pod documented
81 0 ▶sub send_text ($self, %args) { $self->_submit('send_text', %args) }
Subroutine send_text: not called CC=1 SCAR=6.9
Pod documented
82 0 ▶sub capture_pane ($self, %args) { $self->_submit('capture_pane', %args) }
Subroutine capture_pane: not called CC=1 SCAR=6.9
Pod documented
83 0 ▶sub kill_pane ($self, %args) { $self->_submit('kill_pane', %args) }
Subroutine kill_pane: not called CC=1 SCAR=6.9
Pod documented
84 0 ▶sub kill_window ($self, %args) { $self->_submit('kill_window', %args) }
Subroutine kill_window: not called CC=1 SCAR=6.9
Pod documented
85 0 ▶sub kill_session ($self, %args) { $self->_submit('kill_session', %args) }
Subroutine kill_session: not called CC=1 SCAR=6.9
Pod documented
86 0 ▶sub kill_server ($self, %args) { $self->_submit('kill_server', %args) }
Subroutine kill_server: not called CC=1 SCAR=6.9
Pod documented
87 0 ▶sub clients ($self, %args) { $self->_submit('clients', %args) }
Subroutine clients: not called CC=1 SCAR=6.9
Pod documented
88 0 ▶sub attach_argv ($self, %args) { $self->_submit('attach_argv', %args) }
Subroutine attach_argv: not called CC=1 SCAR=6.9
Pod documented
89 0 ▶sub detach_client ($self, %args) { $self->_submit('detach_client', %args) }
Subroutine detach_client: not called CC=1 SCAR=6.9
Pod documented
90 0 ▶sub set_option ($self, %args) { $self->_submit('set_option', %args) }
Subroutine set_option: not called CC=1 SCAR=6.9
Pod documented
91 0 ▶sub get_option ($self, %args) { $self->_submit('get_option', %args) }
Subroutine get_option: not called CC=1 SCAR=6.9
Pod documented
92 0 ▶sub unset_option ($self, %args) { $self->_submit('unset_option', %args) }
Subroutine unset_option: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub set_hook ($self, %args) { $self->_submit('set_hook', %args) }
Subroutine set_hook: not called CC=1 SCAR=6.9
Pod documented
94 0 ▶sub show_hooks ($self, %args) { $self->_submit('show_hooks', %args) }
Subroutine show_hooks: not called CC=1 SCAR=6.9
Pod documented
95 0 ▶sub set_environment ($self, %args) { $self->_submit('set_environment', %args) }
Subroutine set_environment: not called CC=1 SCAR=6.9
Pod documented
96 0 ▶sub get_environment ($self, %args) { $self->_submit('get_environment', %args) }
Subroutine get_environment: not called CC=1 SCAR=6.9
Pod documented
97  
98 0 ▶sub unset_environment ($self, %args) {
Subroutine unset_environment: not called CC=1 SCAR=6.9
Pod documented
99 0 $self->_submit('unset_environment', %args);
100 }
101 0 ▶sub set_buffer ($self, %args) { $self->_submit('set_buffer', %args) }
Subroutine set_buffer: not called CC=1 SCAR=6.9
Pod documented
102 0 ▶sub show_buffer ($self, %args) { $self->_submit('show_buffer', %args) }
Subroutine show_buffer: not called CC=1 SCAR=6.9
Pod documented
103 0 ▶sub delete_buffer ($self, %args) { $self->_submit('delete_buffer', %args) }
Subroutine delete_buffer: not called CC=1 SCAR=6.9
Pod documented
104  
105 =head1 NAME
106  
107 LibTmux::Async::Server - Optional Future facade over the core protocol
108  
109 =head1 SYNOPSIS
110  
111 use v5.44;
112 use IO::Async::Loop::Ppoll;
113 use LibTmux::Async::Server;
114 my $loop = IO::Async::Loop::Ppoll->new;
115 my $server = LibTmux::Async::Server->new(loop => $loop, socket_name => 'owned');
116 my $capture = $server->snapshot;
117 $loop->await($capture);
118 my $panes = $capture->get->panes->where({ active => true });
119 $loop->await($server->close);
120  
121 =head1 METHODS
122  
123 =head2 new
124  
125 C<new(loop =E<gt> $loop, %connection_options)> constructs without I/O.
126 Borrow an L<IO::Async::Loop::Ppoll>; connection options belong to
127 L<LibTmux::Server/new>. C<max_concurrent> and C<max_queue> configure the
128 owned L<LibTmux::Async::Transport>. Its L<backend and signal contract|LibTmux::Async::Transport/new>
129 applies to this facade. No event loop is run implicitly.
130  
131 =head2 close
132  
133 Cancel active operations, suppress subsequent command continuations, reject
134 new operations, and return a fresh cleanup observer L<Future>. Only successful
135 C<is_done> completion proves owned processes and pipes finished. Cancellation
136 of an observer does not cancel cleanup. The caller must drive its borrowed
137 loop through shutdown. No tmux server is destroyed by closing this facade.
138  
139 =head1 CORE OPERATIONS
140  
141 Each operation below returns a L<Future> yielding exactly one value with the
142 corresponding core method's result and error contract. Void core methods yield
143 one C<undef>. Failures contain the original typed core exception. Preparation
144 and result parsing use L<LibTmux::Operation>; no blocking core operation runs
145 inside the event loop. Captured L<LibTmux::Selection> filtering stays local.
146 Cancelling a Future requests process cleanup and prevents later requests; it
147 cannot reverse already accepted mutations. Independent operations may overlap;
148 C<batch> requests remain ordered. C<Future::AsyncAwait> is optional caller syntax.
149  
150 =head2 execute
151  
152 See L<LibTmux::Server/execute> for arguments, returned value, and completion.
153  
154 =head2 cmd
155  
156 See L<LibTmux::Server/cmd> for arguments, returned value, and completion.
157  
158 =head2 new_session
159  
160 See L<LibTmux::Server/new_session> for arguments, returned value, and completion.
161  
162 =head2 new_window
163  
164 See L<LibTmux::Server/new_window> for arguments, returned value, and completion.
165  
166 =head2 split_pane
167  
168 See L<LibTmux::Server/split_pane> for arguments, returned value, and completion.
169  
170 =head2 snapshot
171  
172 See L<LibTmux::Server/snapshot> for arguments, returned value, and completion.
173  
174 =head2 listings
175  
176 See L<LibTmux::Server/listings> for arguments, returned value, and completion.
177  
178 =head2 query_panes
179  
180 See L<LibTmux::Server/query_panes> for arguments, returned value, and completion.
181 Its observer runs inline in void context; a returned L<Future> is ignored.
182 Cancellation before the decision suppresses it. If the observer cancels its
183 query or calls L</close>, cancellation takes precedence over subsequent return
184 or exception delivery. Continue driving the loop until close cleanup completes.
185  
186 =head2 explain_panes
187  
188 See L<LibTmux::Server/explain_panes> for arguments, returned value, and completion.
189  
190 =head2 rename_session
191  
192 See L<LibTmux::Server/rename_session> for arguments, returned value, and completion.
193  
194 =head2 rename_window
195  
196 See L<LibTmux::Server/rename_window> for arguments, returned value, and completion.
197  
198 =head2 link_window
199  
200 See L<LibTmux::Server/link_window> for arguments, returned value, and completion.
201  
202 =head2 unlink_window
203  
204 See L<LibTmux::Server/unlink_window> for arguments, returned value, and completion.
205  
206 =head2 move_window
207  
208 See L<LibTmux::Server/move_window> for arguments, returned value, and completion.
209  
210 =head2 select_window
211  
212 See L<LibTmux::Server/select_window> for arguments, returned value, and completion.
213  
214 =head2 select_pane
215  
216 See L<LibTmux::Server/select_pane> for arguments, returned value, and completion.
217  
218 =head2 select_layout
219  
220 See L<LibTmux::Server/select_layout> for arguments, returned value, and completion.
221  
222 =head2 resize_pane
223  
224 See L<LibTmux::Server/resize_pane> for arguments, returned value, and completion.
225  
226 =head2 set_title
227  
228 See L<LibTmux::Server/set_title> for arguments, returned value, and completion.
229  
230 =head2 send_keys
231  
232 See L<LibTmux::Server/send_keys> for arguments, returned value, and completion.
233  
234 =head2 send_text
235  
236 See L<LibTmux::Server/send_text> for arguments, returned value, and completion.
237  
238 =head2 capture_pane
239  
240 See L<LibTmux::Server/capture_pane> for arguments, returned value, and completion.
241  
242 =head2 kill_pane
243  
244 See L<LibTmux::Server/kill_pane> for arguments, returned value, and completion.
245  
246 =head2 kill_window
247  
248 See L<LibTmux::Server/kill_window> for arguments, returned value, and completion.
249  
250 =head2 kill_session
251  
252 See L<LibTmux::Server/kill_session> for arguments, returned value, and completion.
253  
254 =head2 kill_server
255  
256 See L<LibTmux::Server/kill_server> for arguments, returned value, and completion.
257  
258 =head2 clients
259  
260 See L<LibTmux::Server/clients> for arguments, returned value, and completion.
261  
262 =head2 attach_argv
263  
264 See L<LibTmux::Server/attach_argv> for arguments, returned value, and completion.
265  
266 =head2 detach_client
267  
268 See L<LibTmux::Server/detach_client> for arguments, returned value, and completion.
269  
270 =head2 set_option
271  
272 See L<LibTmux::Server/set_option> for arguments, returned value, and completion.
273  
274 =head2 get_option
275  
276 See L<LibTmux::Server/get_option> for arguments, returned value, and completion.
277  
278 =head2 unset_option
279  
280 See L<LibTmux::Server/unset_option> for arguments, returned value, and completion.
281  
282 =head2 set_hook
283  
284 See L<LibTmux::Server/set_hook> for arguments, returned value, and completion.
285  
286 =head2 show_hooks
287  
288 See L<LibTmux::Server/show_hooks> for arguments, returned value, and completion.
289  
290 =head2 set_environment
291  
292 See L<LibTmux::Server/set_environment> for arguments, returned value, and completion.
293  
294 =head2 get_environment
295  
296 See L<LibTmux::Server/get_environment> for arguments, returned value, and completion.
297  
298 =head2 unset_environment
299  
300 See L<LibTmux::Server/unset_environment> for arguments, returned value, and completion.
301  
302 =head2 set_buffer
303  
304 See L<LibTmux::Server/set_buffer> for arguments, returned value, and completion.
305  
306 =head2 show_buffer
307  
308 See L<LibTmux::Server/show_buffer> for arguments, returned value, and completion.
309  
310 =head2 delete_buffer
311  
312 See L<LibTmux::Server/delete_buffer> for arguments, returned value, and completion.
313  
314 =head2 batch
315  
316 See L<LibTmux::Server/batch> for arguments, returned value, and completion.
317  
318 =cut
« Async/Transport.pm ↑ Summary Async.pm »