| 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
Condition33%1/3
isatty(0) and isatty(1)
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)
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
$ENV{"RUN_TESTS"} // ""
MC/DC100%1/1
$ENV{"RUN_TESTS"} // ""
$ENV{"RUN_TESTS"}
Truth table100%2/2
A
A= $ENV{"RUN_TESTS"}
| |||||||||||||||||||||||||||||
| 64 | 1 | warn "not activating since running in test mode"; | |||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||
| 66 | 1 | possibly_activate | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | 1 | |||||||||||||||||||||||||||