lib/Devel/CallStack.pm

filter: Statementstmt 51.2% 42 / 82 Branchbran 29.3% 17 / 58 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.2% 9 / 13 Podpod 16.6% 1 / 6 totaltotal 42.6% 70 / 164 CC 33 SCAR 35.1
CC
33
Cov
42%
sub
71.4
import
44.3
read
20.0
CRAP 33.5
↑ Summary
1 package Devel::CallStack;
2  
3 2 require 5.006001;
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use vars qw($VERSION
Subroutine BEGIN: called CC=1 SCAR=0.0
8 $Depth $Full $Reverse $Stdout $Stderr $Out $In $Append
9 $Import
10 2 %Cumul);
11  
12 2 $VERSION = '0.19';
13 2 $Depth = 1e9; # If someone has a callstack this deep, we are in trouble.
14 2 $Import = 0;
15  
16 2 ▶sub import {
Subroutine import: called CC=14 SCAR=37.9
17 2 my $class = shift;
18 2 for my $i (@_) {
19 1 ▶ if ($i =~ /^(?:depth=)?(\d+)$/) {
Branch: 8 branches
BranchTrueFalseTotal
if ($i =~ /^(?:depth=)?(\d+)$/) { } 0 1 1
elsif ($i eq 'full') { } 0 1 1
elsif ($i eq 'reverse') { } 0 1 1
elsif ($i eq 'stdout') { } 0 1 1
elsif ($i eq 'stderr') { } 0 1 1
elsif ($i =~ /^out=(.+)/) { } 0 1 1
elsif ($i =~ /^in(?:=(.+))?/) { } 0 1 1
elsif ($i eq 'append') { } 0 1 1
20 0 $Depth = $1;
21 } elsif ($i eq 'full') {
22 0 $Full = 1;
23 } elsif ($i eq 'reverse') {
24 0 $Reverse = 1;
25 } elsif ($i eq 'stdout') {
26 0 $Stdout = 1;
27 } elsif ($i eq 'stderr') {
28 0 $Stderr = 1;
29 } elsif ($i =~ /^out=(.+)/) {
30 0 $Out = $1;
31 } elsif ($i =~ /^in(?:=(.+))?/) {
32 0 ▶ $In = $1 ne "" ? $1 : "callstack.out";
Branch: 1 branch
BranchTrueFalseTotal
$1 ne '' ? : 0 0 0
33 } elsif ($i eq 'append') {
34 0 $Append = 1;
35 } else {
36 1 die "Devel::CallStack::import: '$i' unknown\n";
37 }
38 }
39 1 &set(); # Otherwise we get the import() call stack captured, too.
40 1 ▶ &read($In) if defined $In;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Devel::CallStack::In 0 1 1
41 1 ▶ $Out = "callstack.out" unless defined $Out || $Stdout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Devel::CallStack::Out or $Devel::CallStack::Stdout 1 0 1
Condition33%1/3
defined $Devel::CallStack::Out or $Devel::CallStack::Stdout
l!l&&r!l&&!r
001
MC/DC0%0/2
defined $Devel::CallStack::Out or $Devel::CallStack::Stdout
defined $Devel::CallStack::Out $Devel::CallStack::Stdout
Truth table33%1/3
A or B
A= defined $Devel::CallStack::OutB= $Devel::CallStack::Stdout
ABresult
1X1
011
000
42 1 $Import++; # Import was a success.
43 }
44  
45 1 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod undocumented
46 1 %Cumul = @_;
47 }
48  
49 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
50 0 %Cumul;
51 }
52  
53 2 ▶sub write {
Subroutine write: called CC=9 SCAR=28.4
Pod undocumented
54 2 ▶ if ($Import) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::CallStack::Import) 1 1 2
55 1 my $ofh;
56 1 ▶ if ($Stdout) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Devel::CallStack::Stdout) { } 0 1 1
elsif ($Devel::CallStack::Stderr) { } 0 1 1
elsif (defined $Devel::CallStack::Out) { } 1 0 1
57 0 $ofh = select STDOUT;
58 } elsif ($Stderr) {
59 0 $ofh = select STDERR;
60 } elsif (defined $Out) {
61 1 ▶ my $mode = $Append ? ">>" : ">";
Branch: 1 branch
BranchTrueFalseTotal
$Devel::CallStack::Append ? : 0 1 1
62 1 ▶ unless (open(OUT, "$mode$Out")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open OUT, "$mode$Devel::CallStack::Out") 0 1 1
63 0 die qq[Devel::CallStack::END: failed to open "$Out" for writing: $!\n];
64 }
65 1 $ofh = select OUT;
66 }
67 1 for my $s (sort keys %Cumul) {
68 0 ▶ next if $s =~ /Devel::CallStack/o; # We do not exist.
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /Devel::CallStack/o 0 0 0
69 0 my $d = ($s =~ tr/,/,/) + 1;
70 0 print "$s $d $Cumul{$s}\n";
71 }
72 1 select $ofh;
73 }
74 }
75  
76 0 ▶sub read {
Subroutine read: not called CC=4 SCAR=30.0
Pod undocumented
77 0 my $fn = shift;
78 0 ▶ unless (open(IN, $fn)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open IN, $fn) 0 0 0
79 0 die qq[Devel::CallStack::read: failed to open "$fn" for reading: $!\n];
80 }
81 0 ▶ while (<IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline IN)) 0 0 0
82 0 my ($s, $d, $n) = split;
83 0 ▶ $s = join(",", reverse split(/,/, $s)) if $Reverse;
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::CallStack::Reverse 0 0 0
84 0 $Cumul{$s} += $n;
85 }
86 0 close(IN);
87 }
88  
89 2 ▶sub END {
Subroutine END: called CC=1 SCAR=0.0
90 2 &write();
91 }
92  
93 package DB;
94  
95 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 0 ▶sub DB { }
Subroutine DB: not called CC=1 SCAR=0.0
Pod undocumented
98  
99 2 ▶use vars qw($Full $Depth $Reverse %Cumul);
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 2 *Depth = \$Devel::CallStack::Depth;
102 2 *Full = \$Devel::CallStack::Full;
103 2 *Reverse = \$Devel::CallStack::Reverse;
104 2 *Cumul = \%Devel::CallStack::Cumul;
105  
106 0 ▶sub sub {
Subroutine sub: not called CC=9 SCAR=42.7
Pod documented
107 0 ▶ if (my ($p, $s) = ($DB::sub =~ /^(.+)::(.+)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $DB::sub =~ /^(.+)::(.+)/) 0 0 0
108 0 my @s;
109 0 ▶ if ($Full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DB::Full) { } 0 0 0
110 0 ▶ if (my ($f, $l) = ($DB::sub{$DB::sub} =~ /^(.+):(\d+)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $DB::sub{$DB::sub} =~ /^(.+):(\d+)/) 0 0 0
111 0 @s = ( "$f:$l:${p}::$s" );
112 0 ▶ for (my $i = 0; @s < $Depth; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@s < $DB::Depth) 0 0 0
113 0 my @c = caller($i);
114 0 ▶ last unless @c;
Branch: 1 branch
BranchTrueFalseTotal
unless @c 0 0 0
115 0 push @s, "$c[1]:$c[2]:$c[3]";
116 }
117 }
118 } else {
119 0 @s = ( $DB::sub );
120 0 ▶ for (my $i = 0; @s < $Depth; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@s < $DB::Depth) 0 0 0
121 0 my @c = caller($i);
122 0 ▶ last unless @c;
Branch: 1 branch
BranchTrueFalseTotal
unless @c 0 0 0
123 0 push @s, $c[3];
124 }
125 }
126 $Cumul{
127 0 ▶ join ",", $Reverse ? @s : reverse @s # Ironic, no?
Branch: 1 branch
BranchTrueFalseTotal
$DB::Reverse ? : 0 0 0
128 }++;
129 }
130 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
131 0 &{$DB::sub}(@_);
132 }
133  
134 2 1;
135 __END__
↑ Summary