blib/lib/Devel/OOCallSeq.pm

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 10 Podpod 33.3% 3 / 9 totaltotal 1.7% 3 / 169 CC 31 SCAR 40.7
CC
31
Cov
0%
DB
110.0
sub
72.0
compare
72.0
CRAP 58.8
« blib/lib/UML/Sequence/Raster.pm ↑ Summary blib/lib/Devel/CallSeq.pm »
1 package Devel::OOCallSeq;
2  
3 =head1 NAME
4  
5 OOCallSeq - produces call sequence outlines (like dprofpp -T)
6  
7 =head1 SYNOPSIS
8  
9 perl -d:OOCallSeq script
10 cat tmon.out
11  
12 =head1 DESCRIPTION
13  
14 This profiler is designed to aid in the production of UML sequence diagrams.
15 It is used by UML::Sequence through genericseq.pl and UML::Sequence::PerlOOSeq.
16 (See UML::Sequence::PerlOOSeq for how to use it in practice.)
17  
18 The key differences between the output of this program and dprofpp -T are
19 these:
20  
21 subroutine names show up correctly (DiePair::new not DiePair::BEGIN)
22 subroutine names are preceded by instance names (die1:Die::roll)
23  
24 Output goes to tmon.out and looks like this:
25  
26 main
27 diePair1:DiePair::new
28 die1:Die::new
29 die2:Die::new
30 diePair1:DiePair::roll
31 die1:Die::roll
32 die2:Die::roll
33 diePair1:DiePair::total
34 diePair1:DiePair::doubles
35  
36 =cut
37  
38 package DB;
39  
40 # %next_object_number is keyed by package name storing number of objects seen
41 # in it so far (to use it preincrement it)
42 our %next_object_number;
43 # %objects is keyed by object reference (like HASH(0x1a6f26c)) storing the
44 # number of the object in its class
45 our %objects;
46 our $stack_depth = 0;
47  
48 our $previous_frame;
49 our $depth;
50 our @output;
51  
52 BEGIN {
53 $single = 0;
54 open TMON, ">tmon.out" or die "Couldn't open tmon.out\n";
55 }
56 END {
57 0 ▶ local $" = "";
Subroutine END: not called CC=1 SCAR=6.9
58 0 print TMON "@output";
59 0 close TMON;
60 }
61  
62 sub sub {
63 0 ▶ local $stack_depth = $stack_depth + 1;
Subroutine sub: not called CC=8 SCAR=42.8
Pod documented
64 0 my $i = 0;
65 0 ▶ if (wantarray) { # list context
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
elsif (defined wantarray) { } 0 0 0
66 0 @ret = &$DB::sub;
67 }
68 elsif (defined wantarray) { # scalar context
69 0 $ret = &$DB::sub;
70 0 ▶ if (defined $ret and "$ret" =~ /([^=]*)=(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ret and "$ret" =~ /([^=]*)=(.*)/) 0 0 0
Condition0%0/3
defined $ret and "$ret" =~ /([^=]*)=(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ret and "$ret" =~ /([^=]*)=(.*)/
defined $ret "$ret" =~ /([^=]*)=(.*)/
Truth table0%0/3
A and B
A= defined $retB= "$ret" =~ /([^=]*)=(.*)/
ABresult
0X0
100
111
71 0 my ($type, $key) = ($1, $2);
72 # put it in the hash
73 0 ▶ unless (defined $objects{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $objects{$key}) 0 0 0
74 0 $objects{$key} = ++$next_object_number{$type};
75 }
76 # to find the constructor, walk back through the output until we
77 # see the most recent call at the current stack level
78 0 ▶ for (my $i = scalar @output - 1; $i >= 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
79 0 $output[$i] =~ /(\s+)(.*)/;
80 0 my ($indent, $rest) = ($1, $2);
81 0 ▶ if ( length($indent)/2 == $stack_depth) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($indent) / 2 == $stack_depth) 0 0 0
82 # indents have two spaces, that's why length is over 2
83 0 my $instance_name = "\l$type$objects{$key}";
84 0 $output[$i] = "$indent$instance_name:$rest\n";
85 0 last;
86 }
87 }
88 }
89 0 $ret;
90 }
91 else { # void context
92 0 &$DB::sub;
93 }
94 }
95  
96 sub DB {
97 0 ▶ my ($pack) = caller(0);
Subroutine DB: not called CC=10 SCAR=47.0
Pod undocumented
98 0 ▶ return if ($pack =~ /Dumper/);
Branch: 1 branch
BranchTrueFalseTotal
if $pack =~ /Dumper/ 0 0 0
99 0 my $frame = DB->new();
100  
101 0 ▶ unless ($frame->compare($previous_frame)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($frame->compare($previous_frame)) 0 0 0
102 0 ▶ my $old_depth = $previous_frame->depth() if ref $previous_frame;
Branch: 1 branch
BranchTrueFalseTotal
if ref $previous_frame 0 0 0
103 0 my $new_depth = $frame ->depth();
104  
105 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
106 0 my $output = " " x ($new_depth - 1);
107 0 ▶ if (defined $frame->element(1)) { # if someone called, say so
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frame->element(1)) { } 0 0 0
108 0 my $arg = $frame->arg(1);
109 0 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
110 0 $arg =~ /([^=]*)=(.*)/;
111 0 my ($type, $key) = ($1, $2);
112 0 ▶ if (defined $key and defined $objects{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key and defined $objects{$key}) 0 0 0
Condition0%0/3
defined $key and defined $objects{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and defined $objects{$key}
defined $key defined $objects{$key}
Truth table0%0/3
A and B
A= defined $keyB= defined $objects{$key}
ABresult
0X0
100
111
113 0 $output .= "\l$type$objects{$key}:";
114 }
115 }
116 0 $output .= $frame->subname(1); # . " " . $frame->arg(1);
117 }
118 else { # first call only, it has no parent
119 0 $output .= $frame->package(0);
120 }
121 0 $output .= "\n";
122 0 push @output, $output;
123 }
124 }
125  
126 0 $previous_frame = $frame;
127 }
128  
129 # I can't use the following package statement, caller doesn't set DB::args
130 # unless it's called from the DB package.
131 # package StackFrame;
132  
133 sub new {
134 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
135 0 my $i = 1;
136 0 my $frame = [];
137  
138 0 ▶ while (my ($package, $file, $line, $subname) = caller($i++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller $i++) 0 0 0
139 0 my $arg = $DB::args[-1];
140 0 push @$frame, { pack => $package,
141 file => $file,
142 subname => $subname,
143 arg => $arg,
144 };
145 }
146 0 return bless $frame, $class;
147 }
148  
149 sub compare {
150 0 ▶ my $self = shift;
Subroutine compare: not called CC=8 SCAR=42.8
Pod undocumented
151 0 my $other = shift;
152  
153 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
154 0 ▶ return 0 if (@$self != @$other);
Branch: 1 branch
BranchTrueFalseTotal
if @$self != @$other 0 0 0
155 0 foreach my $element (1 .. @$self) {
156 0 my $self_element = $self ->[$element];
157 0 my $other_element = $other->[$element];
158 no warnings;
159 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
160 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
161 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
162 }
163 0 return 1;
164 }
165  
166 sub depth {
167 0 ▶ my $self = shift;
Subroutine depth: not called CC=2 SCAR=17.9
Pod undocumented
168  
169 0 ▶ return 0 unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
170 0 return @$self;
171 }
172  
173 sub element {
174 0 ▶ my $self = shift;
Subroutine element: not called CC=3 SCAR=24.8
Pod undocumented
175 0 my $number = shift;
176  
177 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
178 0 ▶ if (defined $self->[$number]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[$number]) { } 0 0 0
179 0 return $self->[$number];
180 }
181 else {
182 0 return undef;
183 }
184 }
185  
186 sub package {
187 0 ▶ my $self = shift;
Subroutine package: not called CC=2 SCAR=17.9
Pod documented
188 0 my $element = shift;
189 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
190  
191 0 return $self->[$element]{pack};
192 }
193  
194 sub subname {
195 0 ▶ my $self = shift;
Subroutine subname: not called CC=2 SCAR=17.9
Pod documented
196 0 my $element = shift;
197 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
198  
199 0 return $self->[$element]{subname};
200 }
201  
202 sub arg {
203 0 ▶ my $self = shift;
Subroutine arg: not called CC=2 SCAR=17.9
Pod undocumented
204 0 my $element = shift;
205 0 ▶ return undef unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
206  
207 0 return $self->[$element]{arg};
208 }
209  
210 1;
« blib/lib/UML/Sequence/Raster.pm ↑ Summary blib/lib/Devel/CallSeq.pm »