line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#_{ Encoding and name |
2
|
|
|
|
|
|
|
=encoding utf8 |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
C - Create class diagrams with graphviz. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
C builds on L. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
package GraphViz::Diagram::ClassDiagram; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
17249
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
37
|
|
13
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
14
|
1
|
|
|
1
|
|
716
|
use utf8; |
|
1
|
|
|
|
|
22
|
|
|
1
|
|
|
|
|
6
|
|
15
|
|
|
|
|
|
|
#_} |
16
|
|
|
|
|
|
|
#_{ Version |
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.01 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
24
|
|
|
|
|
|
|
our @ISA = qw(GraphViz::Graph); |
25
|
|
|
|
|
|
|
#_} |
26
|
|
|
|
|
|
|
#_{ Synopsis |
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use GraphViz::Diagram::ClassDiagram; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
#_} |
33
|
|
|
|
|
|
|
#_{ use … |
34
|
1
|
|
|
1
|
|
71
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
97
|
|
35
|
1
|
|
|
1
|
|
455
|
use GraphViz::Diagram::ClassDiagram::Class; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use GraphViz::Diagram::ClassDiagram::GlobalVar; |
37
|
|
|
|
|
|
|
use GraphViz::Graph; |
38
|
|
|
|
|
|
|
#_} |
39
|
|
|
|
|
|
|
#_{ Methods |
40
|
|
|
|
|
|
|
#_{ POD |
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
#_} |
45
|
|
|
|
|
|
|
sub new { #_{ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 new |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $class_diagram = GraphViz::Diagram::ClassDiagram->new('File.pdf'); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Start drawing a class diagram. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $class = shift; |
56
|
|
|
|
|
|
|
my $output_file = shift; |
57
|
|
|
|
|
|
|
my $opts = shift // {}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# TODO: same functionality already used in GraphViz::Diagram::GitRepository |
60
|
|
|
|
|
|
|
my ($file_base_name, $suffix) = $output_file =~ m!(.*)\.([^.]+)$!; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $self = GraphViz::Graph->new($file_base_name); |
63
|
|
|
|
|
|
|
$self -> {suffix } = $suffix; |
64
|
|
|
|
|
|
|
$self -> {nodes_ } = []; |
65
|
|
|
|
|
|
|
$self -> {links } = []; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
bless $self, $class; |
68
|
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} #_} |
71
|
|
|
|
|
|
|
sub title { #_{ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 title |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$class_diagram -> title("Foo classes"); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Start drawing a class diagram. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# TODO: same functionality already used in GraphViz::Diagram::GitRepository |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $self = shift; |
84
|
|
|
|
|
|
|
my $title = shift; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $title_label = $self->label({html => "$title"}); |
87
|
|
|
|
|
|
|
$title_label->loc('t'); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} #_} |
90
|
|
|
|
|
|
|
sub class { #_{ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 class |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $CFoo = $class_diagram -> class("CFoo"); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Add a L to the class diagram |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
my $class_name = shift; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $class = GraphViz::Diagram::ClassDiagram::Class->new($class_name, $self); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
push @{$self->{nodes_ }}, $class; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return $class; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} #_} |
110
|
|
|
|
|
|
|
sub global_var { #_{ |
111
|
|
|
|
|
|
|
#_{ POD |
112
|
|
|
|
|
|
|
=head2 global_var |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $g_foo = $classes -> global_var('foo'); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Add a L to the class diagram.j |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
#_} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
my $global_var_name = shift; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $global_var = GraphViz::Diagram::ClassDiagram::GlobalVar->new($global_var_name, $self); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
push @{$self->{nodes_ }}, $global_var; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
return $global_var; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} #_} |
131
|
|
|
|
|
|
|
sub link { #_{ |
132
|
|
|
|
|
|
|
=head2 link |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$class_diagram->link($class_one , $class_two); |
135
|
|
|
|
|
|
|
$class_diagram->link($class_one , $attribute_three); |
136
|
|
|
|
|
|
|
$class_diagram->link($attribute_four, $class_five); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Connect classes, attributes and methodes one to another. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $self = shift; |
143
|
|
|
|
|
|
|
my $from = shift; |
144
|
|
|
|
|
|
|
my $to = shift; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $link_description = {from => $from, to => $to}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
push @{$self->{links}}, $link_description; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
return $link_description; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
} #_} |
153
|
|
|
|
|
|
|
sub inheritance { #_{ |
154
|
|
|
|
|
|
|
#_{ POD |
155
|
|
|
|
|
|
|
=head2 inheritance |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $class_base = $class_diagram->class("CBase"); |
158
|
|
|
|
|
|
|
my $class_derv = $class_diagram->class("CDerived"); |
159
|
|
|
|
|
|
|
# … |
160
|
|
|
|
|
|
|
$class_diagram->inheritance($class_base, $class_derv); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
It's probably better to use L<< $class_derv->inherits_from($clas_base) >>. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
#_} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $self = shift; |
169
|
|
|
|
|
|
|
my $class_base = shift; |
170
|
|
|
|
|
|
|
my $class_derv = shift; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
croak "ClassDiagram - derives_from, class_base ($class_base) is not a GraphViz::Diagram::ClassDiagram::Class" unless ref $class_base eq 'GraphViz::Diagram::ClassDiagram::Class'; |
173
|
|
|
|
|
|
|
croak "ClassDiagram - derives_from, class_derv ($class_base) is not a GraphViz::Diagram::ClassDiagram::Class" unless ref $class_base eq 'GraphViz::Diagram::ClassDiagram::Class'; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
my $link_description = $self->link($class_base, $class_derv); |
176
|
|
|
|
|
|
|
$link_description -> {inheritance} = 1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} #_} |
179
|
|
|
|
|
|
|
sub create { #_{ |
180
|
|
|
|
|
|
|
#_{ |
181
|
|
|
|
|
|
|
=head2 create |
182
|
|
|
|
|
|
|
$class_diagram -> create(); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Writes the class diagram: |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=over |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * L L |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * Draw L between classes |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
195
|
|
|
|
|
|
|
#_} |
196
|
|
|
|
|
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
for my $class (@{$self->{nodes_ }}) { |
199
|
|
|
|
|
|
|
$class->render(); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
for my $link_description (@{$self->{links}}) { |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $edge = $self->edge( |
204
|
|
|
|
|
|
|
$link_description->{from}->connector_for_links(), |
205
|
|
|
|
|
|
|
$link_description->{to }->connector_for_links |
206
|
|
|
|
|
|
|
); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
if ($link_description->{inheritance}) { |
209
|
|
|
|
|
|
|
$edge->arrow_end('invempty'); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
$self->SUPER::create($self->{suffix}); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
} #_} |
216
|
|
|
|
|
|
|
sub color_comment { #_{ |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 color_comment |
219
|
|
|
|
|
|
|
my $color_comment = GraphViz::Diagram::ClassDiagram::color_comment() |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Static method. Returns the color for comments. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Compare with L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
return '#22c050'; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
} #_} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#_} |
232
|
|
|
|
|
|
|
#_{ Source Code |
233
|
|
|
|
|
|
|
=head1 Source code |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
The source code is on L. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
#_} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
'tq84'; |