lib/FP/Repl/WithRepl.pm

filter: Statementstmt 91.9% 1054 / 1146 Branchbran 2.7% 2 / 74 Conditioncond 11.7% 2 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 95.0% 346 / 364 Podpod 0.0% 0 / 9 totaltotal 86.6% 1404 / 1621 CC 44 SCAR 27.8
CC
44
Cov
86%
have_eval_since_frame
272.0
WithRepl_eval_e
110.0
current_user_frame
72.0
CRAP 16.1
« lib/Chj/xopen.pm ↑ Summary .htmlgen/gen »
1 #
2 # Copyright (c) 2015-2020 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 =head1 NAME
11  
12 FP::Repl::WithRepl
13  
14 =head1 SYNOPSIS
15  
16 use FP::Repl::WithRepl;
17 withrepl { die "foo"; }; # shows the exception, then runs a repl
18 # within the exception context
19  
20 push_withrepl (0); # turn on using a repl globally, but storing the
21 # previous handler on a stack; the argument says
22 # how many levels from the current one to go back
23 # for the search of 'eval' (the WORKAROUND, see
24 # below)
25  
26 WithRepl_eval ...; # like `eval` but transparent for WithRepl
27 # handlers (takes an optional package argument, by
28 # default the caller's package is used)
29  
30 my ($v,$e,$is_error) = WithRepl_eval_e("code",$maybe_package);
31 # unlike WithRepl_eval and eval, this safely
32 # returns the result of the given code, or $e == $@
33 # and $is_error == 1 in case of an exception/error.
34  
35 pop_withrepl; # restore the handler that was pushed last.
36  
37  
38 =head1 DESCRIPTION
39  
40 Sets `$SIG{__DIE__}` to a wrapper that shows the exception then calls
41 a repl from L<FP::Repl>. This means, when getting an exception,
42 instead of terminating the program (with a message), you get a chance
43 to inspect the program state interactively.
44  
45 Note that it currently employs a WORKAROUND to check from within the
46 sig handler whether there's a new `(eval)` frame on the stack between
47 the point of the handler call and the point of the handler
48 installation (or n frames back from there, as per the argument to
49 `push_withrepl`).
50  
51 =head1 NOTE
52  
53 This is alpha software! Read the status section in the package README
54 or on the L<website|http://functional-perl.org/>.
55  
56 =cut
57  
58 package FP::Repl::WithRepl;
59 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 #-- moved up here before any lexicals to avoid their exposure--
64 # Wrapping `eval` calls with a special frame
65 # (`FP::Repl::WithRepl::WithRepl_eval`) that the handler can test for:
66  
67 112 ▶sub WithRepl_eval (&;$) {
Subroutine WithRepl_eval: called CC=6 SCAR=17.9
Pod undocumented
68  
69 # my ($arg, $maybe_package) = @_;
70 112 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 112 112
71 0 ▶ @_ == 1 or fp_croak_arity(1);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
72 0 my ($arg) = @_;
73 0 eval { &$arg() }
74 } else {
75 1 ▶ eval do {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
76 112 ▶ @_ == 1 or @_ == 2 or fp_croak_arity("1 or 2");
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or fp_croak_arity("1 or 2") 112 0 112
Condition33%1/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
11200
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table33%1/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
77 112 my ($arg, $maybe_package) = @_;
78 112 ▶ my $package = $maybe_package // caller;
Condition33%1/3
$maybe_package // caller
l!l&&r!l&&!r
01120
MC/DC0%0/2
$maybe_package // caller
$maybe_package caller
Truth table33%1/3
A // B
A= $maybe_packageB= caller
ABresult
1X1
011
000
79 112 "package $package; $arg"
80 }
81 }
82 }
83  
84 0 ▶sub WithRepl_eval_e {
Subroutine WithRepl_eval_e: not called CC=10 SCAR=47.0
Pod undocumented
85 0 ▶ @_ >= 1 and @_ <= 3 or fp_croak_arity("1-3");
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 3 or fp_croak_arity("1-3") 0 0 0
Condition0%0/3
@_ >= 1 and @_ <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@_ >= 1 and @_ <= 3
@_ >= 1 @_ <= 3
Truth table0%0/3
A and B
A= @_ >= 1B= @_ <= 3
ABresult
0X0
100
111
86  
87 # my ($arg, $maybe_package, $wantarray) = @_;
88 0 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
89 0 die "WithRepl_eval_e only supports string eval";
90 } else {
91 0 my $success = eval do {
92 0 ▶ (@_ >= 1 and @_ <= 3) or fp_croak_arity("1-3");
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 3 or fp_croak_arity("1-3") 0 0 0
Condition0%0/3
@_ >= 1 and @_ <= 3
!ll&&!rl&&r
000
MC/DC0%0/2
@_ >= 1 and @_ <= 3
@_ >= 1 @_ <= 3
Truth table0%0/3
A and B
A= @_ >= 1B= @_ <= 3
ABresult
0X0
100
111
93 0 my ($arg, $maybe_package, $wantarray) = @_;
94 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
95 0 ▶ my $scalar = $wantarray ? "" : "scalar";
Branch: 1 branch
BranchTrueFalseTotal
$wantarray ? : 0 0 0
96 0 "[ $scalar do { package $package; $arg } ]"
97 };
98 0 my ($arg, $maybe_package, $wantarray) = @_; # now can have the lexicals
99 0 ▶ if ($success) { ($wantarray ? $success : $$success[0], $@, '') }
Branch: 2 branches
BranchTrueFalseTotal
if ($success) { } 0 0 0
$wantarray ? : 0 0 0
100 0 else { (undef, $@, 1) }
101 }
102 }
103  
104 1 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
105 1 our @EXPORT = qw(withrepl push_withrepl pop_withrepl);
106 1 our @EXPORT_OK = qw(WithRepl_eval WithRepl_eval_e);
107 1 our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
108  
109 1 ▶use FP::Repl;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 1 ▶use FP::Repl::Stack;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 1 ▶use Chj::TEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 1 ▶use FP::Show;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 1 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 # test that 'no' variables are seen (yeah, could do better)
116 0 ▶TEST { &WithRepl_eval('"Hello $arg"') } ();
Subroutine __ANON__: not called CC=1 SCAR=1.2
117 0 ▶TEST { my ($res, $e, $is_err) = WithRepl_eval_e('"Hello $arg"'); $is_err } 1;
Subroutine __ANON__: not called CC=1 SCAR=2.6
118 0 ▶TEST { my ($res, $e, $is_err) = WithRepl_eval_e('[ $res ]'); $is_err } 1;
Subroutine __ANON__: not called CC=1 SCAR=2.6
119  
120 0 ▶TEST {
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 my ($res, $e, $is_err) = WithRepl_eval_e q{
122 my @a = (qw(a b c));
123 @a
124 }, "foo";
125 0 $res
126 }
127 1 3;
128 0 ▶TEST {
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 0 my ($res, $e, $is_err) = WithRepl_eval_e q{
130 my @a = (qw(a b c));
131 @a
132 }, "foo", 1;
133 0 $res
134 }
135 1 [qw(a b c)];
136  
137 # PROBLEM: even exceptions within contexts that catch exceptions
138 # (i.e. `eval { }`) are invoking a repl, unless we use a workaround.
139  
140 # XXX this will be worrysome slow, and on top of that slower for
141 # bigger stack depths, easily turning algorithms into O(n^2)! Needs a
142 # solution in XS.
143  
144 0 ▶sub current_user_frame {
Subroutine current_user_frame: not called CC=8 SCAR=42.8
Pod undocumented
145 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
146 0 my ($skip) = @_;
147 0 ▶ if ($skip) { $skip >= 0 or die "expecting maybe(natural0), got '$skip'"; }
Branch: 2 branches
BranchTrueFalseTotal
if ($skip) 0 0 0
$skip >= 0 or die "expecting maybe(natural0), got '${skip}'" 0 0 0
148 0 my @v;
149 0 my $i = 0;
150 0 ▶ while ((@v) = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v = caller $i++) 0 0 0
151 0 ▶ if ($v[0] ne "FP::Repl::WithRepl") {
Branch: 1 branch
BranchTrueFalseTotal
if ($v[0] ne "FP::Repl::WithRepl") 0 0 0
152 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
153 0 ▶ unless ((@v) = caller($i + $skip)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@v = caller $i + $skip) 0 0 0
154 0 die "skip value goes beyond the end of the stack";
155 }
156 }
157 0 return FP::Repl::StackFrame->new(undef, @v);
158 }
159 }
160 0 die "???"
161 }
162  
163 # have_eval_since_frame: is ignoring eval from repl. Uh, so hacky. But
164 # otherwise how to enable WithRepl from within a repl? With a special
165 # repl command? But even when previously the handler was enabled, a
166 # new repl should never be disabling it. (It should not change the
167 # handler, just change the catch point. But other exception catchers
168 # should change the haandler, but don't, which is the reason we need
169 # to analyze here.)
170  
171 1 our $debug = 0;
172  
173 0 ▶sub have_eval_since_frame {
Subroutine have_eval_since_frame: not called CC=16 SCAR=56.1
Pod undocumented
174 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
175 0 my ($startframe) = @_;
176  
177 0 my @v;
178 0 my $i = 1;
179  
180 SKIP: {
181 0 ▶ while ((@v) = caller $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v = caller $i++) 0 0 0
182 0 ▶ last SKIP if ($v[0] ne "FP::Repl::WithRepl");
Branch: 1 branch
BranchTrueFalseTotal
if $v[0] ne "FP::Repl::WithRepl" 0 0 0
183 }
184 0 die "???"
185 }
186  
187 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
@v = caller $i++ and do { do { my $f = "FP::Repl::StackFrame"->new(undef, @v); if ($f->equal($startframe)) { warn "reached startframe, thus return false" if $FP::Repl::WithRepl::debug; return ""; } elsif ($f->subroutine eq "(eval)") { if (@v = caller $i++) { my $f = "FP::Repl::StackFrame"->new(undef, @v); my $sub = $f->subroutine; if ($sub =~ /::WithRepl_eval(?:_e)?\z/) { warn "(ignore eval since it's from a WithRepl_eval)" if $FP::Repl::WithRepl::debug; } elsif ($sub =~ /::BEGIN\z/) { warn "(ignore eval since it's from a BEGIN)" if $FP::Repl::WithRepl::debug; } else { warn "GOT eval (standalone)" if $FP::Repl::WithRepl::debug; return 1; } ; } else { warn "GOT eval right at end of stack" if $FP::Repl::WithRepl::debug; return 1; } ; } } } 0 0 0
188 0 my $f = FP::Repl::StackFrame->new(undef, @v);
189 0 ▶ if ($f->equal($startframe)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f->equal($startframe)) { } 0 0 0
elsif ($f->subroutine eq '(eval)') { } 0 0 0
190 0 ▶ warn "reached startframe, thus return false" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $FP::Repl::WithRepl::debug 0 0 0
191 0 return ''
192 } elsif ($f->subroutine eq "(eval)") {
193 0 ▶ if ((@v) = caller $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v = caller $i++) { } 0 0 0
194 0 my $f = FP::Repl::StackFrame->new(undef, @v);
195 0 my $sub = $f->subroutine;
196 0 ▶ if ($sub =~ /::WithRepl_eval(?:_e)?\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sub =~ /::WithRepl_eval(?:_e)?\z/) { } 0 0 0
elsif ($sub =~ /::BEGIN\z/) { } 0 0 0
197 0 ▶ warn "(ignore eval since it's from a WithRepl_eval)"
Branch: 1 branch
BranchTrueFalseTotal
if $FP::Repl::WithRepl::debug 0 0 0
198 if $debug;
199 } elsif ($sub =~ /::BEGIN\z/) {
200  
201 # (why does BEGIN use eval?)
202 0 ▶ warn "(ignore eval since it's from a BEGIN)" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $FP::Repl::WithRepl::debug 0 0 0
203 } else {
204 0 ▶ warn "GOT eval (standalone)" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $FP::Repl::WithRepl::debug 0 0 0
205 0 return 1
206 }
207 } else {
208 0 ▶ warn "GOT eval right at end of stack" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $FP::Repl::WithRepl::debug 0 0 0
209 0 return 1
210 }
211 }
212 } while ((@v) = caller $i++);
213  
214 0 ▶ warn "couldn't find orig frame!" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $FP::Repl::WithRepl::debug 0 0 0
215  
216 # not even tail-calling should be able to do that, unless, not
217 # local'ized, hm XXX non-popped handler.
218 0 0
219 }
220  
221 0 ▶sub handler_for {
Subroutine handler_for: not called CC=2 SCAR=17.9
Pod undocumented
222 0 ▶ @_ == 2 or fp_croak_arity 2;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or fp_croak_arity(2) 0 0 0
223 0 my ($startframe, $orig_handler) = @_;
224 0 ▶ bless sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
225 0 my ($e) = @_;
226  
227 # to show local errors with backtrace:
228 # require Chj::Backtrace; import Chj::Backtrace;
229 0 ▶ if (have_eval_since_frame $startframe) {
Branch: 1 branch
BranchTrueFalseTotal
if (have_eval_since_frame($startframe)) { } 0 0 0
230  
231 #$SIG{__DIE__} = $orig_handler;
232 # ^ helps against the loop but makes the push_withrepl
233 # one-shot, of course
234 #goto &{$orig_handler // sub { die $_[0] }} nah, try:
235 0 ▶ if (defined $orig_handler) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $orig_handler) { } 0 0 0
236  
237 #goto $orig_handler
238 # ^ just doesn't work, seems to undo the looping
239 # protection. so..: -- XX test goto &$orig_handler
240 0 &$orig_handler($e)
241 } else {
242  
243 #warn "no orig_handler, returning";
244 return
245 0 }
246 } else {
247 0 ▶ my $err = $FP::Repl::Repl::maybe_output // *STDERR{IO};
Condition0%0/2
$FP::Repl::Repl::maybe_output // *STDERR{"IO"}
l!l
00
MC/DC0%0/1
$FP::Repl::Repl::maybe_output // *STDERR{"IO"}
$FP::Repl::Repl::maybe_output
Truth table0%0/2
A
A= $FP::Repl::Repl::maybe_output
Aresult
11
00
248 0 print $err "Exception: " . show($e) . "\n";
249  
250 # then what to do upon exiting it? return the value of the
251 # repl? XX repl needs new feature, a "quit this context
252 # with this value". Although not helping anyway since Perl
253 # can't be made to avoid leaving the exception context.
254 0 push_withrepl(0); # XX correct? Argument?
255 0 repl(skip => 1)
256 }
257 0 }, "FP::Repl::WithRepl::Handler" # just to mark, for Chj::Backtrace ugh
258 }
259  
260 0 ▶sub handler {
Subroutine handler: not called CC=2 SCAR=17.9
Pod undocumented
261 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
262 0 my ($skip) = @_;
263 handler_for(current_user_frame($skip), $SIG{__DIE__})
264 0 }
265  
266 0 ▶sub withrepl (&) {
Subroutine withrepl: not called CC=1 SCAR=6.9
Pod undocumented
267 0 local $SIG{__DIE__} = handler(0);
268 0 &{ $_[0] }()
269 }
270  
271 0 ▶TEST {
Subroutine __ANON__: not called CC=1 SCAR=6.9
272 0 ▶ withrepl { 1 + 2 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
273 0 }
274 1 3;
275 0 ▶TEST {
Subroutine __ANON__: not called CC=1 SCAR=6.9
276 0 ▶ [withrepl { "hello", "world" }]
Subroutine __ANON__: not called CC=1 SCAR=6.9
277 }
278 1 ['hello', 'world'];
279  
280 1 our @stack;
281  
282 0 ▶sub push_withrepl {
Subroutine push_withrepl: not called CC=2 SCAR=17.9
Pod undocumented
283 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
284 0 my ($skip) = @_;
285 0 push @stack, $SIG{__DIE__};
286 0 $SIG{__DIE__} = handler($skip);
287 }
288  
289 0 ▶sub pop_withrepl {
Subroutine pop_withrepl: not called CC=2 SCAR=17.9
Pod undocumented
290 0 ▶ @_ == 0 or fp_croak_arity 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 or fp_croak_arity(0) 0 0 0
291 0 $SIG{__DIE__} = pop @stack;
292 }
293  
294 1 1
295  
« lib/Chj/xopen.pm ↑ Summary .htmlgen/gen »