| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CallGraph::Node; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.55'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
7
|
1
|
|
|
1
|
|
528
|
use CallGraph::Dumper; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
472
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CallGraph::Node - represent a subroutine as a node in a call graph |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $sub1 = CallGraph::Node->new(name => 'main', type => 'internal'); |
|
16
|
|
|
|
|
|
|
my $sub2 = CallGraph::Node->new(name => 'mysub', type => 'external'); |
|
17
|
|
|
|
|
|
|
$sub1->add_call($sub2); |
|
18
|
|
|
|
|
|
|
print $sub1->dump; |
|
19
|
|
|
|
|
|
|
my @calls = $sub1->calls; |
|
20
|
|
|
|
|
|
|
my @callers = $sub2->callers; |
|
21
|
|
|
|
|
|
|
print $sub1->name; # prints 'main' |
|
22
|
|
|
|
|
|
|
print $sub1->type; # prints 'internal' |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module creates a node within a "call graph" for a program. A node |
|
27
|
|
|
|
|
|
|
corresponds to a subroutine (or function, method, or whatever it's called), |
|
28
|
|
|
|
|
|
|
and it has the properties 'name' and 'type'. Subroutines are linked to |
|
29
|
|
|
|
|
|
|
one another by 'calls'. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item my $sub = CallGraph::Node->new(option => value, ...) |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Creates a new node. The available options are 'name' and 'type'. These |
|
38
|
|
|
|
|
|
|
properties really don't mean anything as far as CallGraph::Node is concerned. |
|
39
|
|
|
|
|
|
|
However, CallGraph expects the name to be unique within a graph, and uses the |
|
40
|
|
|
|
|
|
|
values 'internal' or 'external'. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub new { |
|
45
|
15
|
|
|
15
|
1
|
41
|
my ($class, %opts) = @_; |
|
46
|
15
|
|
33
|
|
|
120
|
my $self = bless { |
|
47
|
|
|
|
|
|
|
%opts, |
|
48
|
|
|
|
|
|
|
}, ref $class || $class; |
|
49
|
15
|
|
|
|
|
47
|
$self; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item $sub->add_call($sub2) |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Add a link implying that $sub calls $sub2. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_call { |
|
59
|
16
|
|
|
16
|
1
|
20
|
my ($self, $sub) = @_; |
|
60
|
16
|
|
|
|
|
27
|
$self->_add_call($sub); |
|
61
|
16
|
|
|
|
|
106
|
$sub->_add_caller($self); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _add_call { |
|
65
|
16
|
|
|
16
|
|
20
|
my ($self, $sub) = @_; |
|
66
|
16
|
|
|
|
|
29
|
$self->{children}{$sub->name} = $sub; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _add_caller { |
|
70
|
16
|
|
|
16
|
|
16
|
my ($self, $sub) = @_; |
|
71
|
16
|
|
|
|
|
35
|
$self->{parents}{$sub->name} = $sub; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item my @calls = $sub->calls |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Return a list of calls made by $sub. The items in the list are CallGraph::Node |
|
77
|
|
|
|
|
|
|
items themselves. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub calls { |
|
82
|
95
|
|
|
95
|
1
|
111
|
my ($self) = @_; |
|
83
|
95
|
|
|
|
|
90
|
@{$self->{children}}{sort keys %{$self->{children}}}; |
|
|
95
|
|
|
|
|
380
|
|
|
|
95
|
|
|
|
|
278
|
|
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item my @callers = $sub->callers |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Return a list of calls received by $sub. The items in the list are |
|
89
|
|
|
|
|
|
|
CallGraph::Node items themselves. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub callers { |
|
94
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
95
|
0
|
|
|
|
|
0
|
@{$self->{parents}}{sort keys %{$self->{parents}}}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item my $name = $sub->name; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item $sub->name($new_name); |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Get or set the name of the subroutine. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub name { |
|
107
|
165
|
|
|
165
|
1
|
312
|
my ($self) = shift; |
|
108
|
165
|
50
|
|
|
|
263
|
if (@_) { |
|
109
|
0
|
|
|
|
|
0
|
($self->{name}) = @_; |
|
110
|
0
|
|
|
|
|
0
|
$self; |
|
111
|
|
|
|
|
|
|
} else { |
|
112
|
165
|
|
|
|
|
524
|
$self->{name}; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item my $type = $sub->type; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item $sub->type($new_type); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Get or set the type of the subroutine. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub type { |
|
125
|
69
|
|
|
69
|
1
|
75
|
my ($self) = shift; |
|
126
|
69
|
100
|
|
|
|
101
|
if (@_) { |
|
127
|
11
|
|
|
|
|
16
|
($self->{type}) = @_; |
|
128
|
11
|
|
|
|
|
24
|
$self; |
|
129
|
|
|
|
|
|
|
} else { |
|
130
|
58
|
|
|
|
|
229
|
$self->{type}; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item my $dump = $sub->dump(option => value, ...) |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Dump the call graph, starting from $sub, into a string representation. The |
|
137
|
|
|
|
|
|
|
options are passed to L. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub dump { |
|
142
|
6
|
|
|
6
|
1
|
13
|
my ($self, %opts) = @_; |
|
143
|
6
|
|
|
|
|
30
|
CallGraph::Dumper->new(%opts, root => $self)->dump; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 VERSION |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
0.55 |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L, L, L |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 AUTHOR |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Ivan Tubert Eitub@cpan.orgE |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Copyright (c) 2004 Ivan Tubert. All rights reserved. This program is free |
|
166
|
|
|
|
|
|
|
software; you can redistribute it and/or modify it under the same terms as |
|
167
|
|
|
|
|
|
|
Perl itself. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|