lib/FP/Repl/AutoTrap.pm

filter: Statementstmt 85.1% 23 / 27 Branchbran 75.0% 3 / 4 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 78.2% 36 / 46 CC 3 SCAR 8.2
CC
3
Cov
81%
possibly_activate
4.4
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« examples/skip ↑ Summary lib/FP/Collection.pm »
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::AutoTrap -- use FP::Repl::Trap on tty, Chj::Backtrace otherwise
13  
14 =head1 SYNOPSIS
15  
16 use FP::Repl::AutoTrap;
17  
18 =head1 DESCRIPTION
19  
20 This checks whether stdin and stdout are going to a tty, if so, then
21 activate FP::Repl::Trap to trap errors in a repl, otherwise just activate
22 Chj::Backtrace.
23  
24 This is activated at load time unless C<$ENV{RUN_TESTS}> is true. It
25 can be activated expicitly by calling
26 C<FP::Repl::AutoTrap::possibly_activate>.
27  
28 =head1 SEE ALSO
29  
30 L<FP::Repl::Trap>, L<Chj::Backtrace>
31  
32 =head1 NOTE
33  
34 This is alpha software! Read the status section in the package README
35 or on the L<website|http://functional-perl.org/>.
36  
37 =cut
38  
39 package FP::Repl::AutoTrap;
40  
41 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 # Interesting, FP::Repl::Repl::maybe_tty works differently; well makes
46 # sense. So this is the "non-forcing" way to check:
47 2 ▶use POSIX qw(isatty);
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 113 ▶sub possibly_activate {
Subroutine possibly_activate: called CC=3 SCAR=14.8
Pod undocumented
51 113 ▶ if (isatty(0) and isatty(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isatty(0) and isatty(1)) { } 0 113 113
Condition33%1/3
isatty(0) and isatty(1)
!ll&&!rl&&r
11300
MC/DC0%0/2
isatty(0) and isatty(1)
isatty(0) isatty(1)
Truth table33%1/3
A and B
A= isatty(0)B= isatty(1)
ABresult
0X0
100
111
52 0 require FP::Repl::WithRepl;
53 0 import FP::Repl::WithRepl;
54 0 push_withrepl(0);
55 0 1
56 } else {
57 113 require Chj::Backtrace;
58 113 import Chj::Backtrace;
59 113 0
60 }
61 }
62  
63 2 ▶if (($ENV{RUN_TESTS} // '') eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if (($ENV{'RUN_TESTS'} // '') eq '1') { } 1 1 2
Condition100%2/2
$ENV{"RUN_TESTS"} // ""
l!l
11
MC/DC100%1/1
$ENV{"RUN_TESTS"} // ""
$ENV{"RUN_TESTS"}
Truth table100%2/2
A
A= $ENV{"RUN_TESTS"}
Aresult
11
00
64 1 warn "not activating since running in test mode";
65 } else {
66 1 possibly_activate
67 }
68  
69 2 1
« examples/skip ↑ Summary lib/FP/Collection.pm »