blib/lib/Devel/CallSeq.pm

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 25.0% 2 / 8 totaltotal 1.7% 2 / 114 CC 21 SCAR 36.0
CC
21
Cov
0%
compare
72.0
DB
56.0
element
12.0
CRAP 36.8
« blib/lib/Devel/OOCallSeq.pm ↑ Summary blib/lib/UML/Sequence.pm »
1 package Devel::CallSequence;
2  
3 =head1 NAME
4  
5 CallSeq - produces call sequence outlines (like dprofpp -T)
6  
7 =head1 SYNOPSIS
8  
9 perl -d:CallSeq script
10 cat tmon.out
11  
12 =head1 DESCRIPTION
13  
14 This profiler is designed to aid UML::Sequence in producing diagrams.
15 See UML::Sequence::PerlSeq for instructions in its use.
16  
17 The key difference between the output of this program and dprofpp -T is:
18  
19 subroutine names show up correctly (DiePair::new not DiePair::BEGIN)
20  
21 The output goes to tmon.out and looks like this:
22  
23 main
24 DiePair::new
25 Die::new
26 Die::new
27 DiePair::roll
28 Die::roll
29 Die::roll
30 DiePair::total
31 DiePair::doubles
32  
33 =cut
34  
35 package DB;
36  
37 use strict;
38  
39 BEGIN {
40 open TMON, ">tmon.out" or die "Couldn't open tmon.out\n";
41 }
42 END {
43 0 ▶ close TMON;
Subroutine END: not called CC=1 SCAR=6.9
44 }
45  
46 my $previous_frame;
47 my $depth;
48  
49 sub DB {
50 0 ▶ my ($pack) = caller(0);
Subroutine DB: not called CC=7 SCAR=40.3
Pod undocumented
51 0 ▶ return if ($pack =~ /Dumper/);
Branch: 1 branch
BranchTrueFalseTotal
if $pack =~ /Dumper/ 0 0 0
52 0 my $frame = DB->new();
53  
54 0 ▶ unless ($frame->compare($previous_frame)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($frame->compare($previous_frame)) 0 0 0
55 0 ▶ my $old_depth = $previous_frame->depth() if ref $previous_frame;
Branch: 1 branch
BranchTrueFalseTotal
if ref $previous_frame 0 0 0
56 0 my $new_depth = $frame ->depth();
57  
58 0 ▶ if (not defined $old_depth or $new_depth > $old_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $old_depth or $new_depth > $old_depth) 0 0 0
Condition0%0/3
not defined $old_depth or $new_depth > $old_depth
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $old_depth or $new_depth > $old_depth
not defined $old_depth $new_depth > $old_depth
Truth table0%0/3
not(A) or B
A= not defined $old_depthB= $new_depth > $old_depth
ABresult
1X1
011
000
59 0 print TMON " " x ($new_depth - 1);
60 0 ▶ if (defined $frame->element(1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frame->element(1)) { } 0 0 0
61 0 print TMON $frame->subname(1);
62 }
63 else {
64 0 print TMON $frame->package(0);
65 }
66 0 print TMON "\n";
67 }
68 }
69  
70 0 $previous_frame = $frame;
71 }
72  
73 # I can't use the following package statement, caller doesn't set DB::args
74 # unless it's called from the DB package.
75 # package StackFrame;
76  
77 sub new {
78 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my $i = 1;
80 0 my $frame = [];
81  
82 0 ▶ while (my ($package, $file, $line, $subname) = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller $i++) 0 0 0
83 0 my $arg = $DB::args[0];
84 0 push @$frame, { pack => $package,
85 file => $file,
86 subname => $subname,
87 arg => $arg,
88 };
89 }
90 0 return bless $frame, $class;
91 }
92  
93 sub compare {
94 0 ▶ my $self = shift;
Subroutine compare: not called CC=8 SCAR=42.8
Pod undocumented
95 0 my $other = shift;
96  
97 0 ▶ return 0 unless (ref $self and ref $other);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self and ref $other 0 0 0
Condition0%0/3
ref $self and ref $other
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and ref $other
ref $self ref $other
Truth table0%0/3
A and B
A= ref $selfB= ref $other
ABresult
0X0
100
111
98 0 ▶ return 0 if (@$self != @$other);
Branch: 1 branch
BranchTrueFalseTotal
if @$self != @$other 0 0 0
99 0 foreach my $element (1 .. @$self) {
100 0 my $self_element = $self ->[$element];
101 0 my $other_element = $other->[$element];
102 no warnings;
103 0 ▶ return 0 if ($self_element->{pack} ne $other_element->{pack});
Branch: 1 branch
BranchTrueFalseTotal
if $self_element->{"pack"} ne $other_element->{"pack"} 0 0 0
104 0 ▶ return 0 if ($self_element->{file} ne $other_element->{file});
Branch: 1 branch
BranchTrueFalseTotal
if $self_element->{"file"} ne $other_element->{"file"} 0 0 0
105 0 ▶ return 0 if ($self_element->{subname} ne $other_element->{subname});
Branch: 1 branch
BranchTrueFalseTotal
if $self_element->{"subname"} ne $other_element->{"subname"} 0 0 0
106 }
107 0 return 1;
108 }
109  
110 sub depth {
111 0 ▶ my $self = shift;
Subroutine depth: not called CC=2 SCAR=17.9
Pod undocumented
112  
113 0 ▶ return 0 unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
114 0 return @$self;
115 }
116  
117 sub element {
118 0 ▶ my $self = shift;
Subroutine element: not called CC=3 SCAR=24.8
Pod undocumented
119 0 my $number = shift;
120  
121 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
122 0 ▶ if (defined $self->[$number]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[$number]) { } 0 0 0
123 0 return $self->[$number];
124 }
125 else {
126 0 return undef;
127 }
128 }
129  
130 sub package {
131 0 ▶ my $self = shift;
Subroutine package: not called CC=2 SCAR=17.9
Pod documented
132 0 my $element = shift;
133 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
134  
135 0 return $self->[$element]{pack};
136 }
137  
138 sub subname {
139 0 ▶ my $self = shift;
Subroutine subname: not called CC=2 SCAR=17.9
Pod documented
140 0 my $element = shift;
141 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
142  
143 0 return $self->[$element]{subname};
144 }
145  
146 sub arg {
147 0 ▶ my $self = shift;
Subroutine arg: not called CC=2 SCAR=17.9
Pod undocumented
148 0 my $element = shift;
149 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
150  
151 0 return $self->[$element]{arg};
152 }
153  
154 1;
« blib/lib/Devel/OOCallSeq.pm ↑ Summary blib/lib/UML/Sequence.pm »