lib/Chj/Backtrace.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 57.1% 8 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 78.1% 50 / 64 CC 9 SCAR 14.9
CC
9
Cov
77%
__ANON__
8.0
Clean
3.0
import
2.1
CRAP 4.4
« lib/FP/Hash.pm ↑ Summary lib/FP/Repl/StackPlus.pm »
1 # Fri Oct 29 16:30:48 2004 Chris Tarnutzer, tarnutzer@ethlife.ethz.ch
2 #
3 # Copyright 2004 by Chris Tarnutzer, 2005-2020 by Christian Jaeger
4 # Published under the same terms as perl itself
5 #
6  
7 =head1 NAME
8  
9 Chj::Backtrace
10  
11 =head1 SYNOPSIS
12  
13 Add backtrace to all string based exceptions (those thrown by die
14 "somestring").
15  
16 =head1 DESCRIPTION
17  
18 =head1 TODO
19  
20 Use L<Devel::Confess> or L<Carp Always> instead?
21  
22 =head1 NOTE
23  
24 This is alpha software! Read the status section in the package README
25 or on the L<website|http://functional-perl.org/>.
26  
27 =cut
28  
29 package Chj::Backtrace;
30 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # Carp::longmess 'usually' inserts a needless repetition
37 # if the argument was already created by confess:
38 # Hello at (eval 35) line 1.
39 # at (eval 35) line 1
40 # eval 'package calc; no strict \'vars\'; die "Hello"
41 # ...
42 # Clean removes this needless second line/repetition.
43 # (croak creates a different text so the double duty is not removed.)
44  
45 115 ▶sub Clean {
Subroutine Clean: called CC=2 SCAR=10.9
Pod undocumented
46 115 my ($str) = @_;
47 115 $str =~ s/(at [^\n]* line \d+)\.\n (at [^\n]* line \d+)\n/
48 0 ▶ if ($1 eq $2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq $2) { } 0 0 0
49 0 $1.".\n"
50 } else {
51 0 $1.".\n ".$2."\n"
52 }
53 /se;
54 115 $str
55 }
56  
57 9 our $singlestep = 0; #?.
58 9 our $only_confess_if_not_already = 1;
59 9 our $do_confess_objects = 0;
60  
61 122 ▶sub import {
Subroutine import: called CC=2 SCAR=7.3
62  
63 # Do not override any handler that a previous FP::Repl::Trap may
64 # have installed (HACKY):
65 122 ▶ return if $SIG{__DIE__}->$_isa("FP::Repl::WithRepl::Handler");
Branch: 1 branch
BranchTrueFalseTotal
if $SIG{"__DIE__"}->$Chj::Backtrace::_isa("FP::Repl::WithRepl::Handler") 0 122 122
66  
67 116 ▶ $SIG{__DIE__} = sub {
Subroutine __ANON__: called CC=7 SCAR=20.8
68 116 ▶ $DB::single = 1 if $singlestep;
Branch: 1 branch
BranchTrueFalseTotal
if $Chj::Backtrace::singlestep 0 116 116
69 116 ▶ if ($only_confess_if_not_already) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Chj::Backtrace::only_confess_if_not_already) { } 116 0 116
70 116 ▶ if (!$do_confess_objects and ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Chj::Backtrace::do_confess_objects and ref $_[0]) { } 1 115 116
Condition66%2/3
not $Chj::Backtrace::do_confess_objects and ref $_[0]
!ll&&!rl&&r
01151
MC/DC50%1/2
not $Chj::Backtrace::do_confess_objects and ref $_[0]
not $Chj::Backtrace::do_confess_objects ref $_[0]
Truth table66%2/3
not(A) and B
A= not $Chj::Backtrace::do_confess_objectsB= ref $_[0]
ABresult
0X0
100
111
71  
72 # exception object
73 # (ah well, confess does that check anyway!)
74 1 die @_
75 } else {
76  
77 #print STDERR "\n------\n@_\n------\n";
78 115 ▶ if ($_[0] =~ /^[^\n]*line \d+\.\n/s) { # die, not confess.
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] =~ /^[^\n]*line \d+\.\n/s) { } 98 17 115
elsif ($_[0] =~ /^[^\n]*line \d+\n\t/s) { } 0 17 17
79 98 die Clean Carp::longmess @_
80 } elsif ($_[0] =~ /^[^\n]*line \d+\n\t/s) { # confess
81 0 die @_
82 } else { # unsure
83 17 die Clean Carp::longmess @_
84 }
85 }
86 } else {
87 0 die Clean Carp::longmess @_
88 }
89 122 };
90 }
91  
92 9 1;
« lib/FP/Hash.pm ↑ Summary lib/FP/Repl/StackPlus.pm »