lib/FP/Repl/Repl.pm

filter: Statementstmt 18.2% 119 / 652 Branchbran 0.0% 0 / 258 Conditioncond 0.0% 0 / 135 MC/DCmcdc 0.0% 0 / 75 Subroutinesub 24.7% 27 / 109 Podpod 0.0% 0 / 16 totaltotal 11.7% 146 / 1245 CC 184 SCAR 68.3
CC
184
Cov
11%
run
3756.6
__ANON__
937.2
eval_code
342.0
CRAP 929.2
« lib/Chj/HTTP/Daemon.pm ↑ Summary lib/Chj/Class/Array.pm »
1 #
2 # Copyright (c) 2004-2022 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 # Depends: () ; well it does depend on a pager, but which one? It's optional.
11  
12 =head1 NAME
13  
14 FP::Repl::Repl - read-eval-print loop
15  
16 =head1 SYNOPSIS
17  
18 my $repl = new FP::Repl::Repl;
19 $repl->set_prompt("foo> ");
20 # ^ if left undefined, "$package$perhapslevel> " is used
21 $repl->set_historypath("path/to/dir"); # default is ~/.fp-repl_history
22 $repl->set_env_PATH ($safe_PATH); # default in taint mode is
23 # '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
24 # $ENV{PATH} otherwise. Is only used for running tooling for the
25 # repl itself, like the pager.
26 $repl->run;
27 # or $repl->run($skip) to skip $skip levels
28  
29 =head1 DESCRIPTION
30  
31 Enters an interactive read-eval-print loop. Term::ReadLine with
32 history is active. The loop can be exited by typing ctl-d. Entering
33 nothing re-evaluates the last entry. Some autocompletion exists.
34  
35 When the entered line starts with ':' or ',' (both characters are
36 equivalent), then it is interpreted as containing special commands or
37 modes. Enter ':h' or ':help' or ':?' (or the equivalents starting with
38 the comma like ',?', from now on whenever the text days ':' you can
39 also use the comma) to get a help text including the currently active
40 settings.
41  
42 If the 'Maybe_keepResultIn' field is set to a string, the scalar with the
43 given mae is set to either an array holding all the result values (in
44 :l mode) or the result value (in :1 mode).
45  
46 By default, in the :d / :s / :S modes the results of a calculation are
47 carried over to the next entry in $VAR1 etc. as shown by the display
48 of the result. Those are lexical variables.
49  
50 This does not turn on the Perl debugger, hence programs are not slowed
51 down.
52  
53 =head1 FEATURES
54  
55 Read the help text that is displayed by entering ":h", ",h", ":?" or
56 ",?" in the repl.
57  
58 =head1 TODO
59  
60 - 'A::Class-> ' method completion
61 - for '$Foo ->bar<tab>' completion, if $Foo contains a valid class
62 name, use it
63 - maybe '$ans->[1]->' method completion
64  
65 =head1 IDEAS
66  
67 - should stdout and stderr of the evaluation context go to the pager,
68 too?
69 - maybe handle ->SUPER:: completion?
70 - differ between emptylistofcompletions (no &subs for example) (empty
71 list) and no sigil there so dunno-how-to-complete (undef?,
72 exception?, ??).
73 - make package lexicals accessible when entering a package with :p
74  
75 =head1 BUGS
76  
77 Completion:
78  
79 - $ does not filter out scalars only, since perl is not able to do so
80 - % and * make completion stop working unless you put a space after
81 those sigils. (@ and & work as they should)
82 - keep the last 10 or so completion lists, and use those in the ->
83 case if the var's type could not be determined.
84  
85 :V breaks view of :e and similar (shows CODE..)
86  
87  
88 =head1 SEE ALSO
89  
90 L<FP::Repl>: easy wrapper
91  
92 =head1 NOTE
93  
94 This is alpha software! Read the status section in the package README
95 or on the L<website|http://functional-perl.org/>.
96  
97 =cut
98  
99 package FP::Repl::Repl;
100  
101 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 # Copy from FP::Repl::WithRepl, to prevent circular dependency. This has
106 # to be at the top before any lexicals are defined! so that lexicals
107 # from this module are not active in the eval'ed code.
108  
109 0 ▶sub WithRepl_eval (&;$) {
Subroutine WithRepl_eval: not called CC=3 SCAR=24.8
Pod undocumented
110 0 my ($arg, $maybe_package) = @_;
111 0 ▶ if (ref $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg) { } 0 0 0
112 0 eval { &$arg() }
113 } else {
114 0 ▶ my $package = $maybe_package // caller;
Condition0%0/3
$maybe_package // caller
l!l&&r!l&&!r
000
MC/DC0%0/2
$maybe_package // caller
$maybe_package caller
Truth table0%0/3
A // B
A= $maybe_packageB= caller
ABresult
1X1
011
000
115 0 eval "package $package; $arg"
116 }
117 }
118  
119 1 ▶use Chj::Class::methodnames;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 1 ▶use Chj::xoutpipe();
Subroutine BEGIN: called CC=1 SCAR=0.0
121 1 ▶use Chj::xtmpfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 ▶use Chj::xperlfunc qw(xexec xstat);
Subroutine BEGIN: called CC=1 SCAR=0.0
123 1 ▶use Chj::xopen qw(fh_to_fh perhaps_xopen_read);
Subroutine BEGIN: called CC=1 SCAR=0.0
124 1 ▶use POSIX qw(sigaction SIGINT);
Subroutine BEGIN: called CC=1 SCAR=0.0
125 1 ▶use Chj::xhome qw(xsafehome);
Subroutine BEGIN: called CC=1 SCAR=0.0
126 1 ▶use Chj::singlequote 'singlequote';
Subroutine BEGIN: called CC=1 SCAR=0.0
127 1 ▶use FP::HashSet qw(hashset_union);
Subroutine BEGIN: called CC=1 SCAR=0.0
128 1 ▶use FP::Hash qw(hash_xref);
Subroutine BEGIN: called CC=1 SCAR=0.0
129 1 ▶use FP::Repl::StackPlus;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 1 ▶use FP::Lazy;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 1 ▶use FP::Show;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
133 1 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 1 ▶use FP::Array qw(array_take array_last_upto);
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 0 ▶sub maybe_tty {
Subroutine maybe_tty: not called CC=2 SCAR=17.9
Pod undocumented
137 0 my $path = "/dev/tty";
138 0 ▶ if (open my $fh, "+>", $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '+>', $path) { } 0 0 0
139 0 $fh
140 } else {
141 0 warn "opening '$path': $!";
142 undef
143 0 }
144 }
145  
146 0 ▶sub xone_nonwhitespace {
Subroutine xone_nonwhitespace: not called CC=2 SCAR=17.9
Pod undocumented
147 0 my ($str) = @_;
148 0 ▶ $str =~ /^\s*(\S+)\s*\z/s
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /^\s*(\S+)\s*\z/s or die "exactly one non-quoted argument must be given" 0 0 0
149 or die "exactly one non-quoted argument must be given";
150 0 $1
151 }
152  
153 0 ▶sub maybe_fp_repl_home {
Subroutine maybe_fp_repl_home: not called CC=4 SCAR=30.0
Pod undocumented
154 0 ▶ if (my $e = $ENV{FP_REPL_HOME}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $ENV{'FP_REPL_HOME'}) { } 0 0 0
155  
156 # XX todo: properly deal with paths on Windows
157 0 ▶ if (my ($esafe) = $e =~ m{^(/.*)\z}s) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($esafe) = $e =~ m[^(/.*)\z]s) { } 0 0 0
158 0 ▶ if (-d $esafe) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $esafe) { } 0 0 0
159 0 $esafe
160 } else {
161 0 warn "Note: ignoring FP_REPL_HOME (dir does not exist)";
162 undef
163 0 }
164 } else {
165 0 warn "Note: ignoring FP_REPL_HOME (is non-absolute path)";
166 undef
167 0 }
168 } else {
169 undef
170 0 }
171 }
172  
173 # Mis-using lazyLight for impure code here; could be simply a thunk
174 # (procedure with no arguments). *Not* using TransparentLazy since we
175 # better control explicitly where the exposition to side effects
176 # should happen!
177 0 ▶my $HOME = lazyLight { maybe_fp_repl_home() // xsafehome };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
maybe_fp_repl_home() // xsafehome()
l!l&&r!l&&!r
000
MC/DC0%0/2
maybe_fp_repl_home() // xsafehome()
maybe_fp_repl_home() xsafehome()
Truth table0%0/3
A // B
A= maybe_fp_repl_home()B= xsafehome()
ABresult
1X1
011
000
178 0 ▶our $maybe_historypath = lazyLight { force($HOME) . "/.fp-repl_history" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
179 0 ▶our $maybe_settingspath = lazyLight { force($HOME) . "/.fp-repl_settings" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
180 1 our $maxHistLen = 500;
181 1 our $doCatchINT = 1;
182 1 our $doRepeatWhenEmpty = 1;
183 1 our $doKeepResultsInVARX = 1;
184 0 ▶our $pager = lazyLight {
Subroutine __ANON__: not called CC=2 SCAR=17.9
185 0 ▶ $ENV{PAGER} ? [split /\s+/, $ENV{PAGER}] : ["less"]
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PAGER'} ? : 0 0 0
186 1 };
187 1 our $mode_context = 'l';
188 1 our $mode_formatter = 'd';
189 1 our $mode_viewer = 'a';
190 1 our $mode_lexical_persistence = 'X';
191 1 our $maybe_env_path
192  
193 # only used for running tooling for the repl itself, like the
194 # pager, and only if taint mode is on (see commit
195 # 890020b5ac502fe3fd11bf400c4cba70be5c1ac4)
196 = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';
197  
198 1 ▶use Chj::Class::Array -fields => -publica => (
Subroutine BEGIN: called CC=1 SCAR=0.0
199 'Maybe_historypath', # undef=none, but a default is set
200 'Maybe_settingspath', # undef=none, but a default is set
201 'MaxHistLen', 'Maybe_prompt', # undef= build fresh one from package&level
202 'Maybe_package', # undef= use caller's package
203 'DoCatchINT', 'DoRepeatWhenEmpty', 'Maybe_keepResultIn',
204 'DoKeepResultsInVARX', 'Pager', 'Mode_context', # char
205 'Mode_formatter', # char
206 'Mode_viewer', # char
207 'Mode_lexical_persistence', # char
208 'Maybe_input', # fh
209 'Maybe_output', # fh
210 'Maybe_env_PATH', # maybe string
211 1 );
212  
213 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
214 0 my $class = shift;
215 0 my $self = $class->SUPER::new;
216 0 $$self[Maybe_historypath] = force $maybe_historypath;
217 0 $$self[Maybe_settingspath] = force $maybe_settingspath;
218 0 $$self[MaxHistLen] = force $maxHistLen;
219 0 $$self[DoCatchINT] = force $doCatchINT;
220 0 $$self[DoRepeatWhenEmpty] = force $doRepeatWhenEmpty;
221 0 $$self[DoKeepResultsInVARX] = force $doKeepResultsInVARX;
222 0 $$self[Pager] = force $pager;
223 0 $$self[Mode_context] = force $mode_context;
224 0 $$self[Mode_formatter] = force $mode_formatter;
225 0 $$self[Mode_viewer] = force $mode_viewer;
226 0 $$self[Mode_lexical_persistence] = force $mode_lexical_persistence;
227 0 ▶ $$self[Maybe_env_PATH] = force($maybe_env_path) if ${^TAINT};
Branch: 1 branch
BranchTrueFalseTotal
if ${^TAINT} 0 0 0
228 0 $self
229 }
230  
231 8 ▶my $maybe_setter = sub {
Subroutine __ANON__: called CC=1 SCAR=3.5
232 8 my ($method) = @_;
233 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
234 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
235 0 my ($self, $v) = @_;
236 0 my $set_maybe_method = "set_maybe_${method}";
237 0 ▶ defined $v
Branch: 1 branch
BranchTrueFalseTotal
defined $v or die "set_$method does not accept undef, use $set_maybe_method instead" 0 0 0
238 or die
239 "set_${method} does not accept undef, use $set_maybe_method instead";
240 0 $self->$set_maybe_method($v);
241 }
242 8 };
243 1 for my $method (
244 qw(historypath settingspath prompt package keepResultIn
245 input output env_PATH)
246 )
247 {
248 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
249 8 my $var = "set_$method";
250 8 *$var = &$maybe_setter($method);
251 }
252  
253 0 ▶sub use_lexical_persistence {
Subroutine use_lexical_persistence: not called CC=1 SCAR=6.9
Pod undocumented
254 0 my $self = shift;
255 0 hash_xref(+{ m => 1, M => 1, x => 0, X => 0 },
256 $self->mode_lexical_persistence)
257 }
258  
259 0 ▶sub use_strict_vars {
Subroutine use_strict_vars: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my $self = shift;
261 0 hash_xref(+{ m => 1, M => 0, x => 1, X => 0 },
262 $self->mode_lexical_persistence)
263 }
264  
265 1 my $settings_version = "v2";
266 1 my $settings_fields = [
267  
268 # these should remain caller dependent:
269 #maxHistLen
270 #doCatchINT
271 #doRepeatWhenEmpty
272 #maybe_keepResultIn
273 #doKeepResultsInVARX
274 #pager
275 qw(mode_context
276 mode_formatter
277 mode_viewer
278 mode_lexical_persistence)
279 ];
280  
281 0 ▶sub possibly_save_settings {
Subroutine possibly_save_settings: not called CC=2 SCAR=17.9
Pod undocumented
282 0 my $self = shift;
283 0 ▶ if (my $path = $self->maybe_settingspath) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $self->maybe_settingspath) 0 0 0
284 0 my $f = xtmpfile $path;
285 $f->xprint(
286 0 join("\0", $settings_version, map { $self->$_ } @$settings_fields));
287 0 $f->xclose;
288 0 $f->xputback(0600);
289 }
290 }
291  
292 0 ▶sub possibly_restore_settings {
Subroutine possibly_restore_settings: not called CC=5 SCAR=34.0
Pod undocumented
293 0 my $self = shift;
294 0 ▶ if (my $path = $self->maybe_settingspath) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $self->maybe_settingspath) 0 0 0
295 0 ▶ if (my ($f) = perhaps_xopen_read($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($f) = perhaps_xopen_read($path)) 0 0 0
296 0 my @v = split /\0/, $f->xcontent;
297 0 $f->xclose;
298 0 ▶ if (shift(@v) eq $settings_version) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift @v eq $settings_version) { } 0 0 0
299 0 ▶ for (my $i = 0; $i < @$settings_fields; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$settings_fields) 0 0 0
300 0 my $method = "set_" . $$settings_fields[$i];
301 0 $self->$method($v[$i]);
302 }
303 } else {
304 0 warn "note: not reading settings of other version from '$path'";
305 }
306 }
307 }
308 }
309  
310 0 ▶sub saving {
Subroutine saving: not called CC=2 SCAR=17.9
Pod undocumented
311 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
312 0 my ($self, $proc) = @_;
313 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
314 0 &$proc(@_);
315 0 $self->possibly_save_settings;
316 }
317 0 }
318  
319 # (move to some lib?)
320 0 ▶sub splitpackage {
Subroutine splitpackage: not called CC=2 SCAR=17.9
Pod undocumented
321 0 my ($package) = @_; # may be partial.
322 0 ▶ if ($package =~ /(.*)::(.*)/s) { ($1, $2) }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /(.*)::(.*)/s) { } 0 0 0
323 0 else { ("", $package) }
324 }
325  
326 1 my $PACKAGE = qr/\w+(?:::\w+)*/;
327  
328 1 ▶use FP::Repl::corefuncs();
Subroutine BEGIN: called CC=1 SCAR=0.0
329 1 our @builtins = FP::Repl::corefuncs;
330  
331 # whether to use Data::Dumper in perl mode
332 1 our $Dumper_Useperl = 0;
333  
334 0 ▶sub __signalhandler { die "SIGINT\n" }
Subroutine __signalhandler: not called CC=1 SCAR=6.9
335  
336 1 our $term; # local'ized but old value is reused if present.
337  
338 1 our $current_history; # local'ized; array(s).
339  
340 0 ▶my $pagercmd_a = lazyLight {
Subroutine __ANON__: not called CC=2 SCAR=17.9
341 0 my $p = force($pager);
342 0 ▶ if ($p->[0] =~ m{(^|/)less$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->[0] =~ m[(^|/)less$]) { } 0 0 0
343 0 [@$p, qw(--quit-if-one-screen --no-init)];
344 } else {
345 0 $pager
346 }
347 1 };
348  
349 0 ▶sub print_help {
Subroutine print_help: not called CC=1 SCAR=6.9
Pod undocumented
350 0 my $self = shift;
351 0 my ($out) = @_;
352 0 ▶ my $selection = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
353 0 my ($meth, $val) = @_;
354 0 my $method = "mode_$meth";
355 0 ▶ $self->$method eq $val ? "->" : " "
Branch: 1 branch
BranchTrueFalseTotal
$self->$method eq $val ? : 0 0 0
356 0 };
357 0 my $L = &$selection(context => '1');
358 0 my $l = &$selection(context => 'l');
359 0 my $p = &$selection(formatter => 'p');
360 0 my $s = &$selection(formatter => 's');
361 0 my $S = &$selection(formatter => 'S');
362 0 my $d = &$selection(formatter => 'd');
363 0 my $V = &$selection(viewer => 'V');
364 0 my $v = &$selection(viewer => 'v');
365 0 my $a = &$selection(viewer => 'a');
366 0 my $m = &$selection(lexical_persistence => 'm');
367 0 my $M = &$selection(lexical_persistence => 'M');
368 0 my $x = &$selection(lexical_persistence => 'x');
369 0 my $X = &$selection(lexical_persistence => 'X');
370 0 my $pagercmd_pager_str = join(" ", @{ $$self[Pager] });
371 0 my $pagercmd_a_str = join(" ", @{ force $pagercmd_a });
372 0 print $out qq{Repl help:
373 If a command line starts with a ':' or ',', then the remainder of the
374 line is interpreted as follows:
375  
376 package \$package use \$package as new compilation package
377 p \$package shortcut for package
378 DIGITS shorthand for 'f n', see below
379 - same as 'f n' where n is the current frameno - 1
380 + same as 'f n' where n is the current frameno + 1
381 (both are the same as 'f' if reaching the end)
382 CMD args... one-time command
383 MODES code... change some modes then evaluate code
384  
385 CMD is one of:
386 e [n] print lexical environment at level n (default: 0)
387 Note: currently this does *not* show the lexicals that were
388 persisted when enabling m or M mode.
389 b|bt print back trace
390 f [n] move to stack frame number n (at start: 0)
391 without n, shows the current frame again
392 y [n] alias for f
393 q quit the process (by calling `exit`)
394  
395 MODES are a combination of these characters, which change the
396 previously used mode (indicated on the left):
397 context:
398 $L 1 use scalar context
399 $l l use list context (default)
400 formatter:
401 $p P print stringification
402 $s s show from FP::Show (experimental, does not show data sharing)
403 $S S show from FP::Show (ditto), but reformatted via Perl::Tidy
404 $d d Data::Dumper (default)
405 viewer:
406 $V V no pager
407 $v v pipe to pager ('$pagercmd_pager_str')
408 $a a pipe to '$pagercmd_a_str' (default)
409 lexical persistence:
410 (Persisting lexicals means to carry over variables introduced with
411 "my" into subsequent entries in the same repl. It prevents their
412 values from being deallocated until new values are assigned or a
413 new lexical with the same name is introduced. Currently these
414 lexicals are carried over even when moving to another frame or
415 package.)
416 $m m persist lexicals, use strict 'vars'
417 $M M persist lexicals, no strict 'vars'
418 $x x do not persist lexicals, use strict 'vars'
419 $X X do not persist lexicals, no strict 'vars' (default)
420  
421 Other features:
422 \$FP::Repl::Repl::args is an array holding the arguments of the last subroutine call
423 that led to the currently selected frame
424 \$FP::Repl::Repl::argsn is an array holding the arguments of the subroutine call
425 that *leaves* the currently selected frame
426 };
427 }
428  
429 1 our $history_z = 0; # for history file numbering
430  
431 0 ▶sub formatter {
Subroutine formatter: not called CC=3 SCAR=24.8
Pod undocumented
432 0 my $self = shift;
433 0 my ($terse) = @_; # true for :e viewing
434 0 my $mode = $self->mode_formatter;
435 0 ▶ $mode = "d" if ($terse and $mode eq "p");
Branch: 1 branch
BranchTrueFalseTotal
if $terse and $mode eq "p" 0 0 0
Condition0%0/3
$terse and $mode eq "p"
!ll&&!rl&&r
000
MC/DC0%0/2
$terse and $mode eq "p"
$terse $mode eq "p"
Truth table0%0/3
A and B
A= $terseB= $mode eq "p"
ABresult
0X0
100
111
436 0 ▶ my $s_formatter = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
437 0 my $z = 1;
438 my $str = join "", map {
439 0 ▶ my $VARX
Branch: 1 branch
BranchTrueFalseTotal
$self->[8] && !$terse ? : 0 0 0
Condition0%0/3
$self->[8] and not $terse
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[8] and not $terse
$self->[8] not $terse
Truth table0%0/3
A and not(B)
A= $self->[8]B= not $terse
ABresult
0X0
100
111
440 = ($$self[DoKeepResultsInVARX] and not $terse)
441 ? '$VAR' . $z++ . ' = '
442 : '';
443 0 $VARX . show($_) . ";\n"
444 } @_;
445  
446 # HACK to avoid having to use Data::Dumper::AutoEncode
447 0 require Encode;
448 0 $str = Encode::decode('UTF-8', $str, Encode::FB_CROAK());
449 0 $str =~ s/(?<!\\)\\x\{(\w+)\}/chr hex $1/sge;
450 0 $str
451 0 };
452 hash_xref(
453 +{
454 0 ▶ p => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
455 0 ▶ join "", map { (defined $_ ? $_ : 'undef') . "\n" } @_
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
456 },
457 s => $s_formatter,
458 0 ▶ S => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
459 0 my $str = $s_formatter->(@_);
460 0 require Perl::Tidy;
461 0 my $str2;
462 0 Perl::Tidy::perltidy(
463 source => \$str,
464 destination => \$str2,
465 argv => ["--character-encoding=utf8"],
466 );
467 0 $str2
468 },
469 0 ▶ d => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
470 0 my @v = @_; # to survive into
471 # WithRepl_eval below
472  
473 0 require Data::Dumper;
474 0 my $res;
475 0 ▶ WithRepl_eval {
Subroutine __ANON__: not called CC=1 SCAR=6.9
476 0 local $Data::Dumper::Sortkeys = 1;
477 0 local $Data::Dumper::Terse = $terse;
478 0 local $Data::Dumper::Useperl = $Dumper_Useperl;
479 0 $res = Data::Dumper::Dumper(@v);
480 0 1
481 }
482 0 ▶ || do {
Branch: 1 branch
BranchTrueFalseTotal
&WithRepl_eval(sub { local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Terse = $terse; local $Data::Dumper::Useperl = $Dumper_Useperl; $res = Data::Dumper::Dumper(@v); 1; } ) or do { warn 'Data::Dumper: ' . show($@) } 0 0 0
483 0 warn "Data::Dumper: " . show($@);
484 };
485 0 $res
486 }
487 },
488 0 $mode
489 );
490 }
491  
492 0 ▶sub viewers {
Subroutine viewers: not called CC=1 SCAR=6.9
Pod undocumented
493 0 my $self = shift;
494 0 my ($OUTPUT, $ERROR) = @_;
495 0 ▶ my $port_pager_with_perhaps_pagercmd = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
496 0 my (@perhaps_pagercmd) = @_;
497 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
498 0 my ($print_value_to) = @_;
499  
500 0 local $SIG{PIPE} = "IGNORE";
501  
502 my @pagercmd
503 0 ▶ = @perhaps_pagercmd ? @perhaps_pagercmd : @{ $self->pager };
Branch: 1 branch
BranchTrueFalseTotal
@perhaps_pagercmd ? : 0 0 0
504  
505 eval {
506 my $o = Chj::xoutpipe(
507 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
508  
509 # set stdout and stderr in case they are
510 # redirected (stdin is the pipe)
511 0 my $out = fh_to_fh($OUTPUT);
512 0 $out->xdup2(1);
513 0 $out->xdup2(2);
514 0 ▶ $ENV{PATH} = $self->maybe_env_PATH
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->maybe_env_PATH 0 0 0
515 if defined $self->maybe_env_PATH;
516 0 xexec @pagercmd
517 }
518 0 );
519 0 $o->xbinmode(":encoding(utf-8)");
520 0 &$print_value_to($o);
521 0 $o->xfinish;
522 0 1
523 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $o = Chj::xoutpipe(sub { my $out = fh_to_fh($OUTPUT); $out->xdup2(1); $out->xdup2(2); $ENV{"PATH"} = $self->maybe_env_PATH if defined $self->maybe_env_PATH; xexec(@pagercmd); } ); $o->xbinmode(":encoding(utf-8)"); &$print_value_to($o); $o->xfinish; 1 } } or do { my $estr = show($@); unless ($estr =~ /broken pipe/i) { print $ERROR 'error piping to pager, ' . join(" ", @pagercmd) . ": $estr\n" or die $!; } } 0 0 0
524 0 my $estr = show($@);
525 0 ▶ unless ($estr =~ /broken pipe/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($estr =~ /broken pipe/i) 0 0 0
526 0 ▶ print $ERROR "error piping to pager, "
Branch: 1 branch
BranchTrueFalseTotal
print $ERROR 'error piping to pager, ' . join(" ", @pagercmd) . ": $estr\n" or die $! 0 0 0
527 . join(" ", @pagercmd)
528 . ": $estr\n"
529 or die $!;
530 }
531 };
532 }
533 0 };
534  
535 0 ▶ my $string_pager_with_perhaps_pagercmd = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
536 0 my $port_pager = $port_pager_with_perhaps_pagercmd->(@_);
537 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
538 0 my ($v) = @_;
539 $port_pager->(
540 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
541 0 my ($o) = @_;
542 0 $o->xprint($v);
543 }
544 0 );
545 }
546 0 };
547  
548 0 ▶ my $choosepager = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
549 0 my ($pager_with_pagercmd) = @_;
550 hash_xref(
551 +{
552 0 ▶ V => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
553 0 ▶ print $OUTPUT $_[0] or die "print: $!";
Branch: 1 branch
BranchTrueFalseTotal
print $OUTPUT $_[0] or die "print: $!" 0 0 0
554 },
555 v => $pager_with_pagercmd->(),
556 0 a => $pager_with_pagercmd->(@{ force $pagercmd_a}),
557 },
558 $self->mode_viewer
559 );
560 0 };
561  
562 0 ▶ my $pager = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
563 0 my ($pager_with_pagercmd) = @_;
564 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
565 0 my ($v) = @_;
566 0 $choosepager->($pager_with_pagercmd)->($v);
567 }
568 0 };
569  
570 (
571 0 &$pager($port_pager_with_perhaps_pagercmd),
572 &$pager($string_pager_with_perhaps_pagercmd)
573 )
574 }
575  
576 1 our $use_warnings = q{use warnings; use warnings FATAL => 'uninitialized';};
577  
578 0 ▶sub eval_code {
Subroutine eval_code: not called CC=18 SCAR=58.3
Pod undocumented
579 0 my $self = shift;
580 0 ▶ @_ == 5 or fp_croak_arity 5;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 5 or fp_croak_arity(5) 0 0 0
581 0 my ($code, $in_package, $maybe_lexicals, $maybe_kept_results,
582 $maybe_lexical_persistence)
583 = @_;
584  
585 # merge with previous results, if any
586 0 ▶ my $maybe_kept_results_hash = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
587 0 ▶ return unless $maybe_kept_results;
Branch: 1 branch
BranchTrueFalseTotal
unless $maybe_kept_results 0 0 0
588 0 my %r;
589 0 ▶ for (my $i = 0; $i < @$maybe_kept_results; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$maybe_kept_results) 0 0 0
590 0 $r{ '$VAR' . ($i + 1) } = \($$maybe_kept_results[$i]);
591 }
592 0 \%r
593 0 };
594 0 ▶ $maybe_lexicals
Branch: 1 branch
BranchTrueFalseTotal
$maybe_lexicals && $maybe_kept_results ? : 0 0 0
Condition0%0/6
$maybe_lexicals and $maybe_kept_results
!ll&&!rl&&r
000
$maybe_lexicals // &$maybe_kept_results_hash
l!l&&r!l&&!r
000
MC/DC0%0/2
$maybe_lexicals and $maybe_kept_results
$maybe_lexicals $maybe_kept_results
MC/DC0%0/2
$maybe_lexicals // &$maybe_kept_results_hash
$maybe_lexicals &$maybe_kept_results_hash
Truth table0%0/3
A and B
A= $maybe_lexicalsB= $maybe_kept_results
ABresult
0X0
100
111
Truth table0%0/3
A // B
A= $maybe_lexicalsB= &$maybe_kept_results_hash
ABresult
1X1
011
000
595 = ($maybe_lexicals && $maybe_kept_results)
596 ? hashset_union($maybe_lexicals, &$maybe_kept_results_hash)
597 : ($maybe_lexicals // &$maybe_kept_results_hash);
598  
599 0 ▶ my $use_method_signatures
Branch: 1 branch
BranchTrueFalseTotal
$Method::Signatures::VERSION ? : 0 0 0
600 = $Method::Signatures::VERSION ? "use Method::Signatures" : "";
601 0 ▶ my $use_functional_parameters_
Branch: 1 branch
BranchTrueFalseTotal
$Function::Parameters::VERSION ? : 0 0 0
602 = $Function::Parameters::VERSION
603 ? "use Function::Parameters ':strict'"
604 : "";
605 0 ▶ my $use_signatures = ($] >= 5.020) ? "use experimental 'signatures'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.02 ? : 0 0 0
606 0 ▶ my $use_tail = $Sub::Call::Tail::VERSION ? "use Sub::Call::Tail" : "";
Branch: 1 branch
BranchTrueFalseTotal
$Sub::Call::Tail::VERSION ? : 0 0 0
607 0 ▶ my $use_autobox = @FP::autobox::ISA ? "use FP::autobox" : "";
Branch: 1 branch
BranchTrueFalseTotal
@FP::autobox::ISA ? : 0 0 0
608  
609 0 ▶ my $prelude
Branch: 1 branch
BranchTrueFalseTotal
$self->use_strict_vars ? : 0 0 0
610 = "package "
611 . &$in_package() . ";"
612 . "use strict; "
613 . ($self->use_strict_vars ? "" : "no strict 'vars'; ")
614 . "$use_warnings; "
615 . "$use_method_signatures; $use_functional_parameters_; "
616 . "$use_signatures; $use_tail; $use_autobox; ";
617  
618 0 ▶ if (my $lp = $maybe_lexical_persistence) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lp = $maybe_lexical_persistence) { } 0 0 0
619 0 my $allcode = $prelude . $code;
620 0 ▶ if (defined $maybe_lexicals) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maybe_lexicals) 0 0 0
621 0 $lp->lexicals(hashset_union($lp->lexicals, $maybe_lexicals))
622 }
623 0 ▶ my $context = wantarray ? "list" : "scalar"; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
624 0 $lp->context($context);
625 0 ▶ WithRepl_eval { $lp->eval($allcode) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
626 0 } else {
627 0 ▶ my @v = sort keys %{ $maybe_lexicals // {} };
Condition0%0/2
$maybe_lexicals // {}
l!l
00
MC/DC0%0/1
$maybe_lexicals // {}
$maybe_lexicals
Truth table0%0/2
A
A= $maybe_lexicals
Aresult
11
00
628 0 ▶ my $allcode
Branch: 1 branch
BranchTrueFalseTotal
@v ? : 0 0 0
629 = $prelude
630 . (@v ? 'my (' . join(", ", @v) . '); ' : '') . 'sub {'
631 . $code . "\n" . '}';
632 0 ▶ my $thunk = &WithRepl_eval($allcode) // return;
Condition0%0/2
&WithRepl_eval($allcode) // (return)
l!l
00
MC/DC0%0/1
&WithRepl_eval($allcode) // (return)
&WithRepl_eval($allcode)
Truth table0%0/2
A
A= &WithRepl_eval($allcode)
Aresult
11
00
633 0 ▶ PadWalker::set_closed_over($thunk, $maybe_lexicals)
Branch: 1 branch
BranchTrueFalseTotal
if defined $maybe_lexicals 0 0 0
634 if defined $maybe_lexicals;
635 0 ▶ WithRepl_eval { &$thunk() }
Subroutine __ANON__: not called CC=1 SCAR=6.9
636 0 }
637 }
638  
639 0 ▶sub _completion_function {
Subroutine _completion_function: not called CC=1 SCAR=6.3
640 0 my ($attribs, $package, $lexicals) = @_;
641 0 ▶ sub {
Subroutine __ANON__: not called CC=32 SCAR=68.4
642 0 my ($text, $line, $start, $end) = @_;
643 0 my $part = substr($line, 0, $end);
644  
645 #reset to the default before deciding upon it:
646 0 $attribs->{completion_append_character} = " ";
647  
648 0 my @matches = do {
649  
650 # arrow completion:
651 0 my ($pre, $varnam, $brace, $alreadywritten);
652 0 ▶ if (($pre, $varnam, $brace, $alreadywritten)
Branch: 4 branches
BranchTrueFalseTotal
if (() = $part =~ /(.*)\$(\w+)\s*->\s*([{\[]\s*)?(\w*)\z/s or () = $part =~ /(.*\$)\$(\w+)(?:\s+|(?:\s*([{\[]\s*)(\w*)))\z/s) { } 0 0 0
elsif ($part =~ tr/"// % 2) { } 0 0 0
elsif ($part =~ tr/'// % 2) { } 0 0 0
elsif ($part =~ /(^|.)\s*($PACKAGE(?:::)?)\z/s or $part =~ /([\$\@\%\*\&]) \s* ($PACKAGE(?:::)?|) # ^ accept the empty string \z/sx) { } 0 0 0
Condition0%0/3
() = $part =~ /(.*)\$(\w+)\s*->\s*([{\[]\s*)?(\w*)\z/s or () = $part =~ /(.*\$)\$(\w+)(?:\s+|(?:\s*([{\[]\s*)(\w*)))\z/s
l!l&&r!l&&!r
000
MC/DC0%0/2
() = $part =~ /(.*)\$(\w+)\s*->\s*([{\[]\s*)?(\w*)\z/s or () = $part =~ /(.*\$)\$(\w+)(?:\s+|(?:\s*([{\[]\s*)(\w*)))\z/s
() = $part =~ /(.*)\$(\w+)\s*->\s*([{\[]\s*)?(\w*)\z/s () = $part =~ /(.*\$)\$(\w+)(?:\s+|(?:\s*([{\[]\s*)(\w*)))\z/s
Truth table0%0/3
A or B
A= () = $part =~ /(.*)\$(\w+)\s*->\s*([{\[]\s*)?(\w*)\z/sB= () = $part =~ /(.*\$)\$(\w+)(?:\s+|(?:\s*([{\[]\s*)(\w*)))\z/s
ABresult
1X1
011
000
653 = $part =~ /(.*)\$(\w+)\s*->\s*([{\[]\s*)?(\w*)\z/s
654 or ($pre, $varnam, $brace, $alreadywritten)
655 = $part =~ /(.*\$)\$(\w+)(?:\s+|(?:\s*([{\[]\s*)(\w*)))\z/s)
656 {
657 # need to know the class of that thing
658 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
659 0 my $r;
660  
661 # try to get the value, or at least the package.
662 0 my $val = do {
663 0 ▶ if (my $ref = $$lexicals{ '$' . $varnam }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $$lexicals{'$' . $varnam}) { } 0 0 0
664 0 $$ref
665 } else {
666 0 my $v = ${ $package . "::" . $varnam };
667 0 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 0 0 0
668 0 $v
669 } else {
670  
671 # (if I could run code side-effect free... or
672 # compile-only and disassemble....) Try to
673 # parse the perl myself
674 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /.* # force latest possible match (ok?) (?:^|;)\s* (?:(?:my|our)\s+)? # ^ optional for no 'use strict' \$$varnam \s* = \s* (?:new\w*\s+($PACKAGE) |($PACKAGE)\s*->\s*new) /sx) { } 0 0 0
675 $part =~ /.* # force latest possible match (ok?)
676 (?:^|;)\s*
677 (?:(?:my|our)\s+)?
678 # ^ optional for no 'use strict'
679 \$$varnam
680 \s* = \s*
681 (?:new\w*\s+($PACKAGE)
682 |($PACKAGE)\s*->\s*new)
683 /sx
684 )
685 {
686 0 $r = $1;
687 0 1
688 } else {
689 0 0
690 }
691 }
692 }
693 };
694  
695 # Force any potential promises, since we want to
696 # complete methods on the resulting value, OK? TODO
697 # once typing framework is ready (FP::Type): mark type
698 # in promise, thus no need to force it. Have to catch
699 # (and ignore, OK?) exceptions.
700 0 eval { $val = force $val; };
701  
702 0 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
703  
704 #warn "got value from \$$varnam";
705 0 ▶ if ($r ||= ref($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r ||= ref $val) { } 0 0 0
Condition0%0/3
$r ||= ref $val
l!l&&r!l&&!r
000
MC/DC0%0/2
$r ||= ref $val
$r ref $val
Truth table0%0/3
A ||= B
A= $rB= ref $val
ABresult
1X1
011
000
706 0 ▶ if ($r eq 'HASH'
Branch: 6 branches
BranchTrueFalseTotal
if ($r eq 'HASH' or $brace and UNIVERSAL::isa($val, 'HASH')) { } 0 0 0
elsif ($r eq 'ARRAY' or $brace and UNIVERSAL::isa($val, 'ARRAY')) { } 0 0 0
elsif ($r eq 'CODE') { } 0 0 0
elsif ($r eq 'SCALAR') { } 0 0 0
elsif ($r eq 'IO') { } 0 0 0
elsif ($r eq 'GLOB') { } 0 0 0
Condition0%0/6
$r eq "HASH" or $brace and UNIVERSAL::isa($val, "HASH")
l!l&&r!l&&!r
000
$brace and UNIVERSAL::isa($val, "HASH")
!ll&&!rl&&r
000
MC/DC0%0/3
$r eq "HASH" or $brace and UNIVERSAL::isa($val, "HASH")
$r eq "HASH" $brace UNIVERSAL::isa($val, "HASH")
Truth table0%0/4
A or B and C
A= $r eq "HASH"B= $braceC= UNIVERSAL::isa($val, "HASH")
ABCresult
1XX1
0111
00X0
0100
707 or ($brace and UNIVERSAL::isa($val, 'HASH')))
708 {
709 # Could also check `$val->isa('HASH')` if
710 # we wanted to run isa overloads, but
711 # would we want to do that?
712  
713 #("{")
714 #("{foo}","{bar}")
715 0 ▶ if ($brace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($brace) { } 0 0 0
716 0 map {"$_}"} keys %$val
717 } else {
718 0 map {"{$_}"} keys %$val
719 }
720 ▶ } elsif ($r eq 'ARRAY'
Condition0%0/6
$r eq "ARRAY" or $brace and UNIVERSAL::isa($val, "ARRAY")
l!l&&r!l&&!r
000
$brace and UNIVERSAL::isa($val, "ARRAY")
!ll&&!rl&&r
000
MC/DC0%0/3
$r eq "ARRAY" or $brace and UNIVERSAL::isa($val, "ARRAY")
$r eq "ARRAY" $brace UNIVERSAL::isa($val, "ARRAY")
Truth table0%0/4
A or B and C
A= $r eq "ARRAY"B= $braceC= UNIVERSAL::isa($val, "ARRAY")
ABCresult
1XX1
0111
00X0
0100
721 or ($brace and UNIVERSAL::isa($val, 'ARRAY')))
722 {
723 # ^ not sure this works here; see commit messages
724 0 ("[")
725 } elsif ($r eq 'CODE') {
726 0 ("(")
727 } elsif ($r eq 'SCALAR') {
728 0 ("SCALAR") ##
729 } elsif ($r eq 'IO') {
730 0 ("IO") ##
731 } elsif ($r eq 'GLOB') {
732 0 ("GLOB") ##
733 } else {
734  
735 # object
736 0 my @a = methodnames($r);
737 grep {
738 # (no need to check for matching the
739 # already-written part of the string
740 # here (with something like
741 # /^\Q$alreadywritten\E/), why? Maybe
742 # $attribs->{completion_word} was
743 # deleted or?)
744  
745 # exclude some of the possible methodnames:
746 # - all-uppercase when characters are contained.
747 0 ▶ not(/[A-Z]/ and uc($_) eq $_)
Condition0%0/3
/[A-Z]/ && uc $_ eq $_
!ll&&!rl&&r
000
MC/DC0%0/2
/[A-Z]/ && uc $_ eq $_
/[A-Z]/ uc $_ eq $_
Truth table0%0/3
A && B
A= /[A-Z]/B= uc $_ eq $_
ABresult
0X0
100
111
748 } @a
749 }
750 } else {
751 ()
752 0 }
753 } else {
754  
755 #warn "no value from \$$varnam";
756 ()
757 0 }
758 } elsif ($part =~ tr/"/"/ % 2) {
759  
760 # odd number of quotes means we are inside
761 ()
762 0 } elsif ($part =~ tr/'/'/ % 2) {
763  
764 # odd number of quotes means we are inside
765 ()
766 0 ▶ } elsif (
Condition0%0/3
$part =~ /(^|.)\s*($PACKAGE(?:::)?)\z/s or $part =~ /([\$\@\%\*\&]) \s* ($PACKAGE(?:::)?|) # ^ accept the empty string \z/sx
l!l&&r!l&&!r
000
MC/DC0%0/2
$part =~ /(^|.)\s*($PACKAGE(?:::)?)\z/s or $part =~ /([\$\@\%\*\&]) \s* ($PACKAGE(?:::)?|) # ^ accept the empty string \z/sx
$part =~ /(^|.)\s*($PACKAGE(?:::)?)\z/s $part =~ /([\$\@\%\*\&]) \s* ($PACKAGE(?:::)?|) # ^ accept the empty string \z/sx
Truth table0%0/3
A or B
A= $part =~ /(^|.)\s*($PACKAGE(?:::)?)\z/sB= $part =~ /([\$\@\%\*\&]) \s* ($PACKAGE(?:::)?|) # ^ accept the empty string \z/sx
ABresult
1X1
011
000
767 $part =~ /(^|.)\s*(${PACKAGE}(?:::)?)\z/s
768 or $part =~ /([\$\@\%\*\&])
769 \s*
770 (${PACKAGE}(?:::)?|)
771 # ^ accept the empty string
772 \z/sx
773 )
774 {
775 # namespace completion
776 0 my ($sigil, $partialpackage) = ($1, $2);
777  
778 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
779  
780 0 my ($upperpackage, $localpart) = splitpackage($partialpackage);
781  
782 #warn "upperpackage='$upperpackage', localpart='$localpart'\n";
783  
784 # if upperpackage is empty, it might also be a
785 # non-fully qualified, i.e. local, partial identifier.
786  
787 my $globentry = (
788 $sigil and +{
789 '$' => 'SCALAR',
790 '@' => 'ARRAY',
791 '%' => 'HASH',
792  
793 # ^ (problem with readline library, with a space
794 # after % it works too; need better completion
795 # function than the one from gnu readline?)
796 # (years later: what was this?)
797 '*' => 'SCALAR',
798  
799 # ^ really 'GLOB', but that would make it
800 # invisible. SCALAR matches everything, which is
801 # what we want.
802 '&' => 'CODE'
803 0 ▶ }->{$sigil}
Condition0%0/3
$sigil && {'$', 'SCALAR', '@', 'ARRAY', '%', 'HASH', '*', 'SCALAR', '&', 'CODE'}->{$sigil}
!ll&&!rl&&r
000
MC/DC0%0/2
$sigil && {'$', 'SCALAR', '@', 'ARRAY', '%', 'HASH', '*', 'SCALAR', '&', 'CODE'}->{$sigil}
$sigil {'$', 'SCALAR', '@', 'ARRAY', '%', 'HASH', '*', 'SCALAR', '&', 'CODE'}->{$sigil}
Truth table0%0/3
A && B
A= $sigilB= {'$', 'SCALAR', '@', 'ARRAY', '%', 'HASH', '*', 'SCALAR', '&', 'CODE'}->{$sigil}
ABresult
0X0
100
111
804 );
805  
806 #print $ERROR "<$globentry>";
807  
808 0 ▶ my $symbols_for_package = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
809 0 my ($package) = @_;
810 grep {
811 # only show 'usable' ones.
812 0 /^\w+(?:::)?\z/
813 0 } do {
814 0 ▶ if ($globentry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($globentry) { } 0 0 0
815  
816 #print $ERROR ".$globentry.";
817 grep {
818 (
819 /::\z/
820  
821 # either it's a namespace which we
822 # want to see regardless of type, or:
823 # type exists
824 0 ▶ or *{ $package . "::" . $_ }{$globentry}
Condition0%0/2
/::\z/ || *{$package . '::' . $_;}{$globentry}
l!l
00
MC/DC0%0/1
/::\z/ || *{$package . '::' . $_;}{$globentry}
/::\z/
Truth table0%0/2
A
A= /::\z/
Aresult
11
00
825 )
826 0 } keys %{ $package . "::" }
827 } else {
828 0 keys %{ $package . "::" }
829 }
830 }
831 0 };
832 my @a = (
833 $symbols_for_package->($upperpackage),
834  
835 length($upperpackage) ? () : (
836 $symbols_for_package->($package),
837 ($globentry ? () : @builtins),
838  
839 # and lexicals:
840 0 ▶ map { /^\Q$sigil\E(.*)/s ? $1 : () }
Branch: 3 branches
BranchTrueFalseTotal
length $upperpackage ? : 0 0 0
$globentry ? : 0 0 0
/^\Q$sigil\E(.*)/s ? : 0 0 0
841 sort keys %$lexicals
842 )
843 );
844  
845 #print Data::Dumper::Dumper(\@a);
846  
847 # Now, if it ends in ::, or even generally, care about
848 # it not appending space on completion:
849 0 $attribs->{completion_append_character} = "";
850  
851 (
852 map {
853 0 ▶ if (/::\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/::\z/) { } 0 0 0
854 0 $_
855 } else {
856 0 ▶ "$_ "
Branch: 1 branch
BranchTrueFalseTotal
length $upperpackage ? : 0 0 0
857 }
858 } (
859 length($upperpackage)
860 0 ? map { $upperpackage . "::$_" } @a
861 : @a
862 )
863 )
864 } else {
865 ()
866 0 }
867 };
868 0 ▶ if (@matches) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches) { } 0 0 0
869  
870 #print $ERROR "<".join(",",@matches).">";
871  
872 0 $attribs->{completion_word} = \@matches;
873  
874 # (no sorting necessary)
875  
876 return $term->completion_matches($text,
877 $attribs->{list_completion_function})
878 0 } else {
879  
880 # restore defaults.
881 0 $attribs->{completion_append_character} = " ";
882 return ()
883 0 }
884 }
885 0 }
886  
887 1 our $clear_history = do {
888 1 my $did = 0;
889 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
890 0 my ($term) = @_;
891  
892 # Term::ReadLine::Perl does not have clear_history, so, wrap
893 # it. ->can doesn't work either (lazy loading?), so:
894 eval {
895 0 $term->clear_history;
896 0 1
897 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $term->clear_history; 1 } } or do { warn $@ . 'install Term::ReadLine::Gnu if you can' unless $did++ } 0 0 0
898 0 ▶ warn $@ . "install Term::ReadLine::Gnu if you can" unless $did++;
Branch: 1 branch
BranchTrueFalseTotal
unless $did++ 0 0 0
899 }
900 }
901 1 };
902  
903 1 our ($maybe_input, $maybe_output); # dynamic parametrization of
904 # filehandles
905  
906 1 our $repl_level; # maybe number of repl layers above
907 1 our $args; # see '$FP::Repl::Repl::args' in help text
908 1 our $argsn; # see '$FP::Repl::Repl::argsn' in help text
909  
910 # TODO: split this monstrosity into pieces.
911 0 ▶sub run {
Subroutine run: not called CC=62 SCAR=82.3
Pod undocumented
912 0 my ($self, $maybe_skip) = @_;
913  
914 0 ▶ my $skip = $maybe_skip // 0;
Condition0%0/2
$maybe_skip // 0
l!l
00
MC/DC0%0/1
$maybe_skip // 0
$maybe_skip
Truth table0%0/2
A
A= $maybe_skip
Aresult
11
00
915 0 my $stack = FP::Repl::StackPlus->get($skip + 1);
916  
917 0 ▶ local $repl_level = ($repl_level // -1) + 1;
Condition0%0/2
$FP::Repl::Repl::repl_level // -1
l!l
00
MC/DC0%0/1
$FP::Repl::Repl::repl_level // -1
$FP::Repl::Repl::repl_level
Truth table0%0/2
A
A= $FP::Repl::Repl::repl_level
Aresult
11
00
918  
919 0 my $frameno = 0;
920  
921 0 ▶ my $get_package = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
922  
923 # (What is $$self[Maybe_package] for? Can set the maybe_prompt
924 # independently. Security feature or just overengineering?
925 # Ok, remember the ":p" setting; but why not use a lexical
926 # within `run`? Ok how long-lived are the repl objects, same
927 # duration? Then hm is the only reason for the object to be
928 # able to set up things explicitely first? Thus is it ok after
929 # all?)
930 0 ▶ my $r = $$self[Maybe_package] || $stack->package($frameno);
Condition0%0/3
$self->[4] || $stack->package($frameno)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[4] || $stack->package($frameno)
$self->[4] $stack->package($frameno)
Truth table0%0/3
A || B
A= $self->[4]B= $stack->package($frameno)
ABresult
1X1
011
000
931 0 $r
932 0 };
933  
934 0 my $oldsigint = $SIG{INT};
935 eval {
936 0 local $SIG{__DIE__};
937  
938 # It seems this is the only way to make signal handlers work in
939 # both perl 5.6 and 5.8:
940 0 ▶ sigaction SIGINT,
Branch: 1 branch
BranchTrueFalseTotal
sigaction(2, "POSIX::SigAction"->new("FP::Repl::Repl::__signalhandler")) or die "Error setting SIGINT handler: $!\n" 0 0 0
941 POSIX::SigAction->new(__PACKAGE__ . '::__signalhandler')
942 or die "Error setting SIGINT handler: $!\n";
943 0 1
944 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $SIG{"__DIE__"}; sigaction(2, "POSIX::SigAction"->new("FP::Repl::Repl::__signalhandler")) or die "Error setting SIGINT handler: $!\n"; 1 } } or do { if ($^O eq "MSWin32") { $SIG{"INT"} = \&FP::Repl::Repl::__signalhandler; } else { warn "could not set up signal handler: $@ "; } } 0 0 0
945 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
946  
947 # XX will that work?
948 0 $SIG{INT} = \&__signalhandler;
949 } else {
950 0 warn "could not set up signal handler: $@ ";
951 }
952 };
953  
954 {
955 0 local $SIG{__DIE__};
956 0 require Term::ReadLine;
957 }
958  
959 # only start one readline instance, do not nest (doing otherwise
960 # seems to lead to segfaults). okay?.
961 0 ▶ local our $term = $term || Term::ReadLine->new('Repl');
Condition0%0/3
$FP::Repl::Repl::term || 'Term::ReadLine'->new('Repl')
l!l&&r!l&&!r
000
MC/DC0%0/2
$FP::Repl::Repl::term || 'Term::ReadLine'->new('Repl')
$FP::Repl::Repl::term 'Term::ReadLine'->new('Repl')
Truth table0%0/3
A || B
A= $FP::Repl::Repl::termB= 'Term::ReadLine'->new('Repl')
ABresult
1X1
011
000
962  
963 # This means that the history from nested repls will also show up
964 # in the history of the parent repl. Not saved, but within the
965 # readline instance. (Correct?)
966 # XX: idea: add nesting level to history filename?
967  
968 0 my $attribs = $term->Attribs;
969  
970 0 my ($INPUT, $OUTPUT, $ERROR) = do {
971 0 ▶ my $tty = lazy {maybe_tty};
Subroutine __ANON__: not called CC=1 SCAR=6.9
972 0 ▶ my $in = $self->maybe_input // $maybe_input // force($tty) // $term->IN
Condition0%0/12
((($self->maybe_input // $FP::Repl::Repl::maybe_input) // force($tty)) // $FP::Repl::Repl::term->IN) // *STDIN
l!l&&r!l&&!r
000
(($self->maybe_input // $FP::Repl::Repl::maybe_input) // force($tty)) // $FP::Repl::Repl::term->IN
l!l&&r!l&&!r
000
($self->maybe_input // $FP::Repl::Repl::maybe_input) // force($tty)
l!l&&r!l&&!r
000
$self->maybe_input // $FP::Repl::Repl::maybe_input
l!l&&r!l&&!r
000
MC/DC0%0/5
((($self->maybe_input // $FP::Repl::Repl::maybe_input) // force($tty)) // $FP::Repl::Repl::term->IN) // *STDIN
$self->maybe_input $FP::Repl::Repl::maybe_input force($tty) $FP::Repl::Repl::term->IN *STDIN
Truth table0%0/6
A // B // C // D // E
A= $self->maybe_inputB= $FP::Repl::Repl::maybe_inputC= force($tty)D= $FP::Repl::Repl::term->INE= *STDIN
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
973 // *STDIN;
974 0 ▶ my $out = $self->maybe_output // $maybe_output // force($tty)
Condition0%0/12
((($self->maybe_output // $FP::Repl::Repl::maybe_output) // force($tty)) // $FP::Repl::Repl::term->OUT) // *STDOUT
l!l&&r!l&&!r
000
(($self->maybe_output // $FP::Repl::Repl::maybe_output) // force($tty)) // $FP::Repl::Repl::term->OUT
l!l&&r!l&&!r
000
($self->maybe_output // $FP::Repl::Repl::maybe_output) // force($tty)
l!l&&r!l&&!r
000
$self->maybe_output // $FP::Repl::Repl::maybe_output
l!l&&r!l&&!r
000
MC/DC0%0/5
((($self->maybe_output // $FP::Repl::Repl::maybe_output) // force($tty)) // $FP::Repl::Repl::term->OUT) // *STDOUT
$self->maybe_output $FP::Repl::Repl::maybe_output force($tty) $FP::Repl::Repl::term->OUT *STDOUT
Truth table0%0/6
A // B // C // D // E
A= $self->maybe_outputB= $FP::Repl::Repl::maybe_outputC= force($tty)D= $FP::Repl::Repl::term->OUTE= *STDOUT
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
975 // $term->OUT // *STDOUT;
976 0 $term->newTTY($in, $out);
977 0 ($in, $out, $out)
978 };
979  
980 # carry over input/output to subshells:
981 0 local $maybe_input = $INPUT;
982 0 local $maybe_output = $OUTPUT;
983  
984 0 ▶ my $printerror_frameno = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
985 0 my $max = $stack->max_frameno;
986 0 ▶ print $ERROR "frame number must be between 0..$max",
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
987 (@_ ? ", got @_" : ()), "\n";
988 0 };
989  
990 0 my ($view_with_port, $view_string) = $self->viewers($OUTPUT, $ERROR);
991  
992 {
993 0 my @history;
994 0 local $current_history = \@history;
995  
996 # ^ this is what nested repl's will use to restore the history
997 # in the $term object
998  
999 # ^ TODO?: this is, now that history items are written to disk
1000 # immediately, inconsistent!
1001 0 ▶ if (defined $$self[Maybe_historypath]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]) 0 0 0
1002  
1003 # clean history of readline object before we re-add the
1004 # saved one:
1005 0 $clear_history->($term);
1006 0 ▶ my $copyhist = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1007 0 for (@history) {
1008 0 $term->addhistory($_);
1009 }
1010 0 };
1011 0 ▶ if (opendir my $dir, $$self[Maybe_historypath]) {
Branch: 3 branches
BranchTrueFalseTotal
if (opendir my $dir, $self->[0]) { } 0 0 0
elsif (open my $hist, '<', $self->[0]) { } 0 0 0
elsif (-e $self->[0]) { } 0 0 0
1012  
1013 # new style history dirs (each entry its own file)
1014 0 my @items = readdir $dir;
1015 0 ▶ closedir $dir
Branch: 1 branch
BranchTrueFalseTotal
closedir $dir or die "reading dir '$self->[0]': $!" 0 0 0
1016 or die "reading dir '$$self[Maybe_historypath]': $!";
1017 my @fstats
1018 0 ▶ = sort { $a->[2] <=> $b->[2] or $a->[0] cmp $b->[0] } map {
Condition0%0/3
$FP::Repl::Repl::a->[2] <=> $FP::Repl::Repl::b->[2] || $FP::Repl::Repl::a->[0] cmp $FP::Repl::Repl::b->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$FP::Repl::Repl::a->[2] <=> $FP::Repl::Repl::b->[2] || $FP::Repl::Repl::a->[0] cmp $FP::Repl::Repl::b->[0]
$FP::Repl::Repl::a->[2] <=> $FP::Repl::Repl::b->[2] $FP::Repl::Repl::a->[0] cmp $FP::Repl::Repl::b->[0]
Truth table0%0/3
A || B
A= $FP::Repl::Repl::a->[2] <=> $FP::Repl::Repl::b->[2]B= $FP::Repl::Repl::a->[0] cmp $FP::Repl::Repl::b->[0]
ABresult
1X1
011
000
1019 0 ▶ if ($_ eq "." or $_ eq "..") {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq '.' or $_ eq '..') { } 0 0 0
Condition0%0/3
$_ eq "." or $_ eq ".."
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "." or $_ eq ".."
$_ eq "." $_ eq ".."
Truth table0%0/3
A or B
A= $_ eq "."B= $_ eq ".."
ABresult
1X1
011
000
1020 ()
1021 0 } else {
1022 0 my $file = "$$self[Maybe_historypath]/$_";
1023 0 [$_, $file, xstat($file)->mtime]
1024 }
1025 } @items;
1026 0 my @files = map { $_->[1] } @fstats;
1027  
1028 0 my @h;
1029 0 for my $file (@{ array_last_upto \@files, $$self[MaxHistLen] })
1030 {
1031 0 ▶ if (open my $in, "<", $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $in, '<', $file) { } 0 0 0
1032 0 local $/;
1033 0 my $cnt = <$in>;
1034 0 ▶ close $in or die "reading '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
close $in or die "reading '${file}': $!" 0 0 0
1035 0 push @h, $cnt;
1036 } else {
1037 0 warn "can't open file '$file' for reading: $!";
1038 }
1039 }
1040 0 @history = @h;
1041 0 $copyhist->();
1042  
1043 # and clean up stale entries
1044 0 ▶ if (@files > $$self[MaxHistLen]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files > $self->[2]) 0 0 0
1045 0 for my $file (
1046 0 @{ array_take \@files, @files - $$self[MaxHistLen] })
1047 {
1048 0 unlink $file
1049 }
1050 }
1051 } elsif (open my $hist, "<", $$self[Maybe_historypath]) {
1052  
1053 # old style history files
1054 0 @history = do {
1055 0 local $/ = "\n";
1056 0 my @h = <$hist>;
1057 0 chomp @h;
1058 0 @{ array_last_upto(\@h, $$self[MaxHistLen]) }
1059 };
1060 0 ▶ close $hist or die "reading '$$self[Maybe_historypath]': $!";
Branch: 1 branch
BranchTrueFalseTotal
close $hist or die "reading '$self->[0]': $!" 0 0 0
1061 0 $copyhist->();
1062  
1063 # and convert it to files
1064 0 unlink $$self[Maybe_historypath];
1065 0 ▶ mkdir $$self[Maybe_historypath], 0700
Branch: 1 branch
BranchTrueFalseTotal
mkdir $self->[0], 448 or die "can't mkdir($self->[0]): $!" 0 0 0
1066 or die "can't mkdir($$self[Maybe_historypath]): $!";
1067 0 my $z = 0;
1068 0 for my $entry (@history) {
1069  
1070 # c- for converted, also, 'c' < 'n'
1071 0 my $name = sprintf 'c-%06i-%06i', $$, $z++;
1072 0 my $path = "$$self[Maybe_historypath]/$name";
1073  
1074 # No need to be careful here with overwrites as
1075 # conversion happens only once, OK?
1076 0 ▶ open my $out, ">", $path
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $path or die "can't write to '${path}': $!" 0 0 0
1077 or die "can't write to '$path': $!";
1078 0 ▶ print $out $entry or die "can't write to '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
print $out $entry or die "can't write to '${path}': $!" 0 0 0
1079 0 ▶ close $out or die "can't write to '$path': $!";
Branch: 1 branch
BranchTrueFalseTotal
close $out or die "can't write to '${path}': $!" 0 0 0
1080 }
1081 } elsif (-e $$self[Maybe_historypath]) {
1082 0 warn "can't load history from '$$self[Maybe_historypath]': $!";
1083 }
1084 }
1085  
1086 # do not add input to history automatically (which allows me
1087 # to do it myself):
1088 0 $term->MinLine(undef);
1089  
1090 0 ▶ my $myreadline = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
1091 DO: {
1092 0 my $line;
1093 eval {
1094 0 ▶ $line
Branch: 2 branches
BranchTrueFalseTotal
$FP::Repl::Repl::repl_level ? : 0 0 0
$frameno ? : 0 0 0
Condition0%0/2
$self->[3] // &$get_package() . ($FP::Repl::Repl::repl_level ? " $FP::Repl::Repl::repl_level" : "") . ($frameno ? "/$frameno" : "") . '> '
l!l
00
MC/DC0%0/1
$self->[3] // &$get_package() . ($FP::Repl::Repl::repl_level ? " $FP::Repl::Repl::repl_level" : "") . ($frameno ? "/$frameno" : "") . '> '
$self->[3]
Truth table0%0/2
A
A= $self->[3]
Aresult
11
00
1095 = $term->readline($$self[Maybe_prompt]
1096 // &$get_package()
1097 . ($repl_level ? " $repl_level" : "")
1098 . ($frameno ? "/$frameno" : "")
1099 . "> ");
1100 0 1
1101 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $line = $FP::Repl::Repl::term->readline($self->[3] // &$get_package() . ($FP::Repl::Repl::repl_level ? " $FP::Repl::Repl::repl_level" : "") . ($frameno ? "/$frameno" : "") . '> '); 1 } } or do { if (not length ref $@ and $@ =~ /^SIGINT\n/s) { print $OUTPUT "\n"; redo DO; } else { die $@; } } 0 0 0
1102 0 ▶ if (!length ref($@) and $@ =~ /^SIGINT\n/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length ref $@ and $@ =~ /^SIGINT\n/s) { } 0 0 0
Condition0%0/3
not length ref $@ and $@ =~ /^SIGINT\n/s
!ll&&!rl&&r
000
MC/DC0%0/2
not length ref $@ and $@ =~ /^SIGINT\n/s
not length ref $@ $@ =~ /^SIGINT\n/s
Truth table0%0/3
not(A) and B
A= not length ref $@B= $@ =~ /^SIGINT\n/s
ABresult
0X0
100
111
1103 0 print $OUTPUT "\n";
1104 0 redo DO;
1105 } else {
1106 0 die $@
1107 }
1108 };
1109 0 return $line;
1110 }
1111 0 };
1112  
1113 # for repetitions:
1114 0 ▶ my $evaluator = sub { }; # noop
Subroutine __ANON__: not called CC=1 SCAR=6.9
1115  
1116 0 my $maybe_kept_results;
1117  
1118 my $maybe_lexical_persistence;
1119 0 ▶ my $try_enable_lexical_persistence = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1120 eval {
1121 0 require Eval::WithLexicals;
1122 0 $maybe_lexical_persistence = Eval::WithLexicals->new;
1123 0 ▶ eval { require strictures }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require strictures } } or $maybe_lexical_persistence->prelude("") 0 0 0
1124 or $maybe_lexical_persistence->prelude("");
1125 0 1
1126 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Eval::WithLexicals; $maybe_lexical_persistence = "Eval::WithLexicals"->new; eval { do { require strictures } } or $maybe_lexical_persistence->prelude(""); 1 } } or do { print $ERROR 'Could not enable lexical persistence: ' . show($@); 0 } 0 0 0
1127 0 print $ERROR "Could not enable lexical persistence: "
1128 . show($@);
1129 0 0
1130 }
1131 0 };
1132 0 ▶ &$try_enable_lexical_persistence() if $self->use_lexical_persistence;
Branch: 1 branch
BranchTrueFalseTotal
if $self->use_lexical_persistence 0 0 0
1133  
1134 READ: {
1135 0 while (1) {
1136  
1137 local $attribs->{attempted_completion_function}
1138 0 ▶ = _completion_function($attribs, &$get_package,
Condition0%0/2
$stack->perhaps_lexicals($frameno) // {}
l!l
00
MC/DC0%0/1
$stack->perhaps_lexicals($frameno) // {}
$stack->perhaps_lexicals($frameno)
Truth table0%0/2
A
A= $stack->perhaps_lexicals($frameno)
Aresult
11
00
1139 $stack->perhaps_lexicals($frameno) // {});
1140  
1141 0 ▶ my $input = &$myreadline // last;
Condition0%0/2
&$myreadline // (last)
l!l
00
MC/DC0%0/1
&$myreadline // (last)
&$myreadline
Truth table0%0/2
A
A= &$myreadline
Aresult
11
00
1142  
1143 0 ▶ if (length $input) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $input) { } 0 0 0
elsif ($self->[6]) { } 0 0 0
1144  
1145 0 ▶ my ($cmd, $rest)
Branch: 1 branch
BranchTrueFalseTotal
$input =~ /^ *[:,] *([?+-]|[a-zA-Z]+|\d+)(.*)/s ? : 0 0 0
1146 = $input =~ /^ *[:,] *([?+-]|[a-zA-Z]+|\d+)(.*)/s
1147 ? ($1, $2)
1148 : (undef, $input);
1149  
1150 0 ▶ if ( defined $$self[Maybe_historypath]
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0] and not defined $cmd && $cmd eq "q" and not @history && $input eq $history[-1]) 0 0 0
Condition0%0/12
defined $self->[0] and not defined $cmd && $cmd eq "q" and not @history && $input eq $history[-1]
!ll&&!rl&&r
000
defined $self->[0] and not defined $cmd && $cmd eq "q"
!ll&&!rl&&r
000
defined $cmd && $cmd eq 'q'
!ll&&!rl&&r
000
@history && $input eq $history[-1]
!ll&&!rl&&r
000
MC/DC0%0/5
defined $self->[0] and not defined $cmd && $cmd eq "q" and not @history && $input eq $history[-1]
defined $self->[0] defined $cmd $cmd eq 'q' @history $input eq $history[-1]
Truth table0%0/8
A and not(B && C) and not(D && E)
A= defined $self->[0]B= defined $cmdC= $cmd eq 'q'D= @historyE= $input eq $history[-1]
ABCDEresult
0XXXX0
111XX0
10X110
110110
10X0X1
10X101
1100X1
110101
1151 and not(defined $cmd and $cmd eq 'q')
1152 and not(@history and $input eq $history[-1]))
1153 {
1154 0 eval {
1155 TRY: {
1156 # n- for new, also 'n' > 'c'
1157 0 my $name = sprintf 'n-%06i-%06i', $$,
1158 $history_z++;
1159 0 my $path = "$$self[Maybe_historypath]/$name";
1160 0 ▶ if (-e $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path) 0 0 0
1161 0 $history_z++;
1162 0 redo TRY;
1163 }
1164 0 mkdir $$self[Maybe_historypath], 0700;
1165 0 my $f = xtmpfile $path;
1166 0 $f->xprint($input);
1167 0 $f->xclose;
1168 0 $f->xputback(0600);
1169 }
1170  
1171 # cleaning of old entries happens on reading
1172 };
1173 0 ▶ if (ref $@ or $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $@ or $@) 0 0 0
Condition0%0/3
ref $@ or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $@ or $@
ref $@ $@
Truth table0%0/3
A or B
A= ref $@B= $@
ABresult
1X1
011
000
1174 0 warn "could not write history file: " . show($@)
1175 }
1176 }
1177  
1178 0 ▶ if (defined $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cmd) 0 0 0
1179  
1180 0 ▶ if ($cmd =~ /^\d+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^\d+\z/) 0 0 0
1181  
1182 # hacky way to allow ":5" etc. as ":f 5"
1183 0 $rest = "$cmd $rest";
1184 0 $cmd = "f";
1185 }
1186  
1187 # handle commands
1188 eval {
1189  
1190 0 ▶ my $set_package = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1191  
1192 # (no package parsing, trust user)
1193 0 $$self[Maybe_package]
1194 = xone_nonwhitespace($rest);
1195 0 $rest = ""; # XX HACK
1196 0 };
1197  
1198 0 ▶ my $help = sub { $self->print_help($OUTPUT) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1199  
1200 0 ▶ my $bt = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1201 0 ▶ my ($maybe_frameno)
Branch: 1 branch
BranchTrueFalseTotal
my($maybe_frameno) = $rest =~ /^\s*(\d+)?\s*\z/ or die "expecting digits or no argument, got '${cmd}'" 0 0 0
1202 = $rest =~ /^\s*(\d+)?\s*\z/
1203 or die
1204 "expecting digits or no argument, got '$cmd'";
1205 0 local $FP::Lazy::allow_access = 1;
1206  
1207 # ^ XX should be generalized, not just
1208 # for FP::Lazy; or alternatively, use
1209 # overload::StrVal instead of
1210 # stringification in the backtrace
1211 # library.
1212 0 ▶ print $OUTPUT $stack->backtrace($maybe_frameno
Condition0%0/3
$maybe_frameno // $frameno
l!l&&r!l&&!r
000
MC/DC0%0/2
$maybe_frameno // $frameno
$maybe_frameno $frameno
Truth table0%0/3
A // B
A= $maybe_framenoB= $frameno
ABresult
1X1
011
000
1213 // $frameno);
1214 0 $rest = ""; # XX HACK; also, really
1215 # silently drop stuff?
1216 0 };
1217  
1218 0 ▶ my $chooseframe = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1219 0 my ($maybe_frameno) = @_;
1220 0 $rest = ""; # still the hack, right?
1221 0 ▶ if (defined $maybe_frameno) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maybe_frameno) 0 0 0
1222 0 ▶ if ($maybe_frameno <= $stack->max_frameno) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_frameno <= $stack->max_frameno) { } 0 0 0
1223 0 $frameno = $maybe_frameno
1224 } else {
1225 0 &$printerror_frameno($maybe_frameno);
1226 0 return;
1227 }
1228 }
1229  
1230 # unset any explicit package as
1231 # we want to use the one of the
1232 # current frame
1233 0 undef $$self[Maybe_package]
1234 ; # even without frameno? mess
1235  
1236 # Show the context: (XX same
1237 # issue as with :e with overly
1238 # long data (need viewer, but
1239 # don't really want to, so should
1240 # really use shortener)
1241 0 print $OUTPUT $stack->desc(
1242 $frameno, $self->mode_formatter
1243 ),
1244 "\n";
1245 0 };
1246  
1247 0 ▶ my $select_frame = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1248 0 ▶ my ($maybe_frameno)
Branch: 1 branch
BranchTrueFalseTotal
my($maybe_frameno) = $rest =~ /^\s*(\d+)?\s*\z/ or die 'expecting frame number, ' . "an integer, or nothing, got '${cmd}'" 0 0 0
1249 = $rest =~ /^\s*(\d+)?\s*\z/
1250 or die "expecting frame number, "
1251 . "an integer, or nothing, got '$cmd'";
1252 0 &$chooseframe($maybe_frameno)
1253 0 };
1254  
1255 my %commands = (
1256 h => $help,
1257 help => $help,
1258 '?' => $help,
1259 0 ▶ '-' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1260 0 ▶ &$chooseframe(
Branch: 1 branch
BranchTrueFalseTotal
$frameno > 0 ? : 0 0 0
1261 ($frameno > 0) ? $frameno - 1 : undef)
1262 },
1263 0 ▶ '+' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1264 0 ▶ &$chooseframe(
Branch: 1 branch
BranchTrueFalseTotal
$frameno < $stack->max_frameno ? : 0 0 0
1265 ($frameno < $stack->max_frameno)
1266 ? $frameno + 1
1267 : undef)
1268 },
1269 package => $set_package,
1270 p => $set_package,
1271 1 => saving(
1272 0 ▶ $self, sub { $$self[Mode_context] = "1" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1273 ),
1274 l => saving(
1275 0 ▶ $self, sub { $$self[Mode_context] = "l" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1276 ),
1277 P => saving(
1278 0 ▶ $self, sub { $$self[Mode_formatter] = "p" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1279 ),
1280 s => saving(
1281 0 ▶ $self, sub { $$self[Mode_formatter] = "s" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1282 ),
1283 S => saving(
1284 0 ▶ $self, sub { $$self[Mode_formatter] = "S" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1285 ),
1286 d => saving(
1287 0 ▶ $self, sub { $$self[Mode_formatter] = "d" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1288 ),
1289 V => saving(
1290 0 ▶ $self, sub { $$self[Mode_viewer] = "V" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1291 ),
1292 v => saving(
1293 0 ▶ $self, sub { $$self[Mode_viewer] = "v" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1294 ),
1295 a => saving(
1296 0 ▶ $self, sub { $$self[Mode_viewer] = "a" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1297 ),
1298 m => saving(
1299 $self,
1300 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1301 0 ▶ &$try_enable_lexical_persistence()
Branch: 1 branch
BranchTrueFalseTotal
&$try_enable_lexical_persistence() and $self->[13] = "m" 0 0 0
1302 and $$self[Mode_lexical_persistence]
1303 = "m"
1304 }
1305 ),
1306 M => saving(
1307 $self,
1308 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1309 0 ▶ &$try_enable_lexical_persistence()
Branch: 1 branch
BranchTrueFalseTotal
&$try_enable_lexical_persistence() and $self->[13] = "M" 0 0 0
1310 and $$self[Mode_lexical_persistence]
1311 = "M"
1312 }
1313 ),
1314 x => saving(
1315 $self,
1316 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1317 0 undef $maybe_lexical_persistence;
1318 0 $$self[Mode_lexical_persistence] = "x"
1319 }
1320 ),
1321 X => saving(
1322 $self,
1323 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1324 0 undef $maybe_lexical_persistence;
1325 0 $$self[Mode_lexical_persistence] = "X"
1326 }
1327 ),
1328 0 ▶ e => sub {
Subroutine __ANON__: not called CC=4 SCAR=27.0
1329 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
1330  
1331 # XX clean up: don't want i in the regex
1332 0 ▶ my ($maybe_frameno)
Branch: 1 branch
BranchTrueFalseTotal
my($maybe_frameno) = $rest =~ /^i?\s*(\d+)?\s*\z/ or die "expecting digits or no argument, got '${cmd}'" 0 0 0
1333 = $rest =~ /^i?\s*(\d+)?\s*\z/
1334 or die
1335 "expecting digits or no argument, got '$cmd'";
1336 0 $rest = ""
1337 ; # can't s/// above when expecting value
1338 0 ▶ my $fno = $maybe_frameno // $frameno;
Condition0%0/3
$maybe_frameno // $frameno
l!l&&r!l&&!r
000
MC/DC0%0/2
$maybe_frameno // $frameno
$maybe_frameno $frameno
Truth table0%0/3
A // B
A= $maybe_framenoB= $frameno
ABresult
1X1
011
000
1339 0 ▶ if (my ($lexicals)
Branch: 1 branch
BranchTrueFalseTotal
if (my($lexicals) = $stack->perhaps_lexicals($fno)) { } 0 0 0
1340 = $stack->perhaps_lexicals($fno))
1341 {
1342 &$view_with_port(
1343 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1344 0 my ($o) = @_;
1345 0 my $format
1346 = $self->formatter(1);
1347 0 for my $key (
1348 sort keys %$lexicals)
1349 {
1350 0 ▶ if ($key =~ /^\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^\$/) { } 0 0 0
1351 $o->xprint(
1352 "$key = "
1353 . &$format(
1354 ${
1355 0 $$lexicals{
1356 0 $key}
1357 }
1358 )
1359 );
1360 } else {
1361 $o->xprint(
1362 "\\$key = "
1363 . &$format(
1364 0 $$lexicals{$key}
1365 )
1366 );
1367 }
1368 }
1369 }
1370 0 );
1371 } else {
1372 0 &$printerror_frameno($fno);
1373 }
1374 },
1375 f => $select_frame,
1376 y => $select_frame,
1377 0 ▶ q => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1378  
1379 # XX change exit code depending
1380 # on how the repl was called?
1381 # Well, at least make it a config
1382 # field?
1383 0 exit 0
1384 },
1385 0 bt => $bt,
1386 b => $bt,
1387 );
1388  
1389 0 ▶ while (length $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $cmd) 0 0 0
1390  
1391 # XX why am I checking with and without chopping here?
1392 0 ▶ if (my $sub = $commands{$cmd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $commands{$cmd}) { } 0 0 0
1393 0 &$sub;
1394 0 last;
1395 } else {
1396 0 my $subcmd = chop $cmd;
1397 0 ▶ if (my $sub = $commands{$subcmd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $commands{$subcmd}) { } 0 0 0
1398 0 &$sub;
1399 0 last; # XX why last? shouldn't we
1400 # continue with what's left of
1401 # $cmd ?
1402 } else {
1403 0 print $ERROR "unknown command "
1404 . "or mode: '$subcmd'\n";
1405 0 last;
1406 }
1407 }
1408 }
1409  
1410 1
1411 0 ▶ } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $set_package = sub { $self->[4] = xone_nonwhitespace($rest); $rest = ""; } ; my $help = sub { $self->print_help($OUTPUT); } ; my $bt = sub { my($maybe_frameno) = $rest =~ /^\s*(\d+)?\s*\z/ or die "expecting digits or no argument, got '${cmd}'"; local $FP::Lazy::allow_access = 1; print $OUTPUT $stack->backtrace($maybe_frameno // $frameno); $rest = ""; } ; my $chooseframe = sub { my($maybe_frameno) = @_; $rest = ""; if (defined $maybe_frameno) { if ($maybe_frameno <= $stack->max_frameno) { $frameno = $maybe_frameno; } else { &$printerror_frameno($maybe_frameno); return; } ; } ; undef $self->[4]; print $OUTPUT $stack->desc($frameno, $self->mode_formatter), "\n"; } ; my $select_frame = sub { my($maybe_frameno) = $rest =~ /^\s*(\d+)?\s*\z/ or die 'expecting frame number, ' . "an integer, or nothing, got '${cmd}'"; &$chooseframe($maybe_frameno); } ; my(%commands) = ("h", $help, "help", $help, "?", $help, "-", sub { &$chooseframe($frameno > 0 ? $frameno - 1 : undef); } , "+", sub { &$chooseframe($frameno < $stack->max_frameno ? $frameno + 1 : undef); } , "package", $set_package, "p", $set_package, 1, saving($self, sub { $self->[10] = 1; } ), "l", saving($self, sub { $self->[10] = "l"; } ), "P", saving($self, sub { $self->[11] = "p"; } ), "s", saving($self, sub { $self->[11] = "s"; } ), "S", saving($self, sub { $self->[11] = "S"; } ), "d", saving($self, sub { $self->[11] = "d"; } ), "V", saving($self, sub { $self->[12] = "V"; } ), "v", saving($self, sub { $self->[12] = "v"; } ), "a", saving($self, sub { $self->[12] = "a"; } ), "m", saving($self, sub { &$try_enable_lexical_persistence() and $self->[13] = "m"; } ), "M", saving($self, sub { &$try_enable_lexical_persistence() and $self->[13] = "M"; } ), "x", saving($self, sub { undef $maybe_lexical_persistence; $self->[13] = "x"; } ), "X", saving($self, sub { undef $maybe_lexical_persistence; $self->[13] = "X"; } ), "e", sub { my($maybe_frameno) = $rest =~ /^i?\s*(\d+)?\s*\z/ or die "expecting digits or no argument, got '${cmd}'"; $rest = ""; my $fno = $maybe_frameno // $frameno; if (my($lexicals) = $stack->perhaps_lexicals($fno)) { &$view_with_port(sub { my($o) = @_; my $format = $self->formatter(1); foreach my $key (sort keys %$lexicals) { if ($key =~ /^\$/) { $o->xprint("$key = " . &$format(${$$lexicals{$key};})); } else { $o->xprint("\\$key = " . &$format($lexicals->{$key})); } ; } ; } ); } else { &$printerror_frameno($fno); } ; } , "f", $select_frame, "y", $select_frame, "q", sub { exit 0; } , "bt", $bt, "b", $bt); while (length $cmd) { if (my $sub = $commands{$cmd}) { &$sub; last; } else { my $subcmd = chop $cmd; if (my $sub = $commands{$subcmd}) { &$sub; last; } else { print $ERROR 'unknown command ' . "or mode: '${subcmd}'\n"; last; } ; } ; } ; 1 } } or do { print $ERROR "error handling command ${cmd}: " . show($@); redo READ } 0 0 0
1412 0 print $ERROR "error handling command $cmd: "
1413 . show($@);
1414 0 redo READ;
1415 }
1416 }
1417  
1418 # build up evaluator
1419 0 my $eval = do {
1420 0 ▶ my $eval_ = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1421 0 ▶ $self->eval_code(
Condition0%0/2
$stack->perhaps_lexicals($frameno) // {}
l!l
00
MC/DC0%0/1
$stack->perhaps_lexicals($frameno) // {}
$stack->perhaps_lexicals($frameno)
Truth table0%0/2
A
A= $stack->perhaps_lexicals($frameno)
Aresult
11
00
1422 $rest,
1423 $get_package,
1424 $stack->perhaps_lexicals($frameno) // {},
1425 $maybe_kept_results,
1426 $maybe_lexical_persistence
1427 )
1428 0 };
1429 hash_xref(
1430 +{
1431 0 ▶ 1 => sub { ([scalar &$eval_()], $@) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1432 0 ▶ l => sub { ([&$eval_()], $@) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1433 },
1434 0 $self->mode_context
1435 );
1436 };
1437  
1438 0 my $format_vals = $self->formatter;
1439  
1440 0 ▶ $evaluator = sub {
Subroutine __ANON__: not called CC=9 SCAR=43.0
1441 0 my ($results, $error) = do {
1442  
1443 # make it possible for the code entered in
1444 # the repl to access the arguments in the
1445 # last call leading to this position by
1446 # accessing $FP::Repl::Repl::args :
1447 0 ▶ my $getframe = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1448 0 my ($i) = @_;
1449 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $frame = $stack->frame($frameno + $i))) { } 0 0 0
1450 defined(
1451 my $frame = $stack->frame($frameno + $i)
1452 )
1453 )
1454 {
1455 0 $frame->args
1456 } else {
1457 0 "TOP"
1458 }
1459 0 };
1460 0 local $argsn = &$getframe(0);
1461 0 local $args = &$getframe(1);
1462 0 &$eval()
1463 };
1464  
1465 &$view_string(
1466 0 do {
1467 0 ▶ if (ref $error or $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $error or $error) { } 0 0 0
Condition0%0/3
ref $error or $error
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $error or $error
ref $error $error
Truth table0%0/3
A or B
A= ref $errorB= $error
ABresult
1X1
011
000
1468 0 ▶ my $err = (
Branch: 1 branch
BranchTrueFalseTotal
defined builtin::blessed($error) && $error->can('plain') ? : 0 0 0
Condition0%0/3
defined builtin::blessed($error) and $error->can("plain")
!ll&&!rl&&r
000
MC/DC0%0/2
defined builtin::blessed($error) and $error->can("plain")
defined builtin::blessed($error) $error->can("plain")
Truth table0%0/3
A and B
A= defined builtin::blessed($error)B= $error->can("plain")
ABresult
0X0
100
111
1469 (defined blessed $error)
1470 && $error->can("plain")
1471 ?
1472  
1473 # error in plaintext; XX:
1474 # change to better
1475 # thought-out protocol?
1476 $error->plain
1477 : show($error)
1478 );
1479 0 chomp $err;
1480 0 $err . "\n"
1481 ; # no prefix? no safe way to differentiate.
1482 } else {
1483 0 ▶ if (my $varname
Branch: 1 branch
BranchTrueFalseTotal
if (my $varname = $self->[7]) 0 0 0
1484 = $$self[Maybe_keepResultIn])
1485 {
1486 0 ▶ $varname
Branch: 1 branch
BranchTrueFalseTotal
unless $varname =~ /::/ 0 0 0
1487 = &$get_package() . "::$varname"
1488 unless $varname =~ /::/;
1489 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1490 0 ▶ $$varname
Branch: 1 branch
BranchTrueFalseTotal
$self->mode_context eq '1' ? : 0 0 0
1491 = $self->mode_context eq "1"
1492 ? $$results[0]
1493 : $results;
1494 }
1495 0 &$format_vals(@$results)
1496 }
1497 }
1498 );
1499 0 ▶ $maybe_kept_results = $results
Branch: 1 branch
BranchTrueFalseTotal
if $self->[8] 0 0 0
1500 if $$self[DoKeepResultsInVARX];
1501 0 };
1502  
1503 0 &$evaluator();
1504  
1505 } elsif ($$self[DoRepeatWhenEmpty]) {
1506 0 &$evaluator();
1507 } else {
1508 0 next;
1509 }
1510  
1511 0 ▶ if (length $input
Branch: 1 branch
BranchTrueFalseTotal
if (length $input and !defined($history[-1]) || $history[-1] ne $input) 0 0 0
Condition0%0/6
length $input and !defined($history[-1]) || $history[-1] ne $input
!ll&&!rl&&r
000
not defined $history[-1] or $history[-1] ne $input
l!l&&r!l&&!r
000
MC/DC0%0/3
length $input and !defined($history[-1]) || $history[-1] ne $input
length $input not defined $history[-1] $history[-1] ne $input
Truth table0%0/4
A and not(B) or C
A= length $inputB= not defined $history[-1]C= $history[-1] ne $input
ABCresult
0XX0
1000
11X1
1011
1512 and ((!defined $history[-1]) or $history[-1] ne $input))
1513 {
1514 # XX this is, now that entries are written to disk
1515 # immediately, only used for nested repls (see
1516 # todo above)
1517 0 push @history, $input;
1518 0 chomp $input;
1519 0 $term->addhistory($input);
1520  
1521 #splice @history,0,@history-$$self[MaxHistLen] = ();
1522 0 ▶ if ($$self[MaxHistLen] >= 0) { # <-prevent endless loop
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[2] >= 0) 0 0 0
1523 0 ▶ shift @history while @history > $$self[MaxHistLen];
Branch: 1 branch
BranchTrueFalseTotal
@history > $self->[2] and do { shift @history } 0 0 0
1524 }
1525 }
1526 }
1527 }
1528 0 print $OUTPUT "\n";
1529 0 ▶ $SIG{INT} = defined($oldsigint) ? $oldsigint : "DEFAULT";
Branch: 1 branch
BranchTrueFalseTotal
defined $oldsigint ? : 0 0 0
1530  
1531 # (Is there no other return path from sub run? should I use
1532 # DESTROY objects for this? -> nope, no returns, but if
1533 # exceptions not trapped it would fail)
1534 }
1535  
1536 # restore previous history, if any
1537 0 ▶ if ($current_history) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FP::Repl::Repl::current_history) 0 0 0
1538 0 $clear_history->($term);
1539 0 for (@$current_history) {
1540 0 chomp;
1541 0 $term->addhistory($_);
1542 }
1543 }
1544 }
1545  
1546 1 end Chj::Class::Array;
1547  
1548 # for backwards compatibility:
1549 1 *set_maxhistlen = *set_maxHistLen{CODE};
1550 1 *set_docatchint = *set_doCatchINT{CODE};
1551 1 *set_dorepeatwhenempty = *set_doRepeatWhenEmpty{CODE};
1552 1 *set_maybe_keepresultin = *set_maybe_keepResultIn{CODE};
1553  
« lib/Chj/HTTP/Daemon.pm ↑ Summary lib/Chj/Class/Array.pm »