line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Graph::Writer::XML - write a directed graph out as XML |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Graph::Writer::XML; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
89752
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
402
|
use parent 'Graph::Writer'; |
|
1
|
|
|
|
|
231
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
637
|
use XML::Writer; |
|
1
|
|
|
|
|
5339
|
|
|
1
|
|
|
|
|
333
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '2.07'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#======================================================================= |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# _write_graph() - perform the writing of the graph |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# This is invoked from the public write_graph() method, |
20
|
|
|
|
|
|
|
# and is where the actual writing of the graph happens. |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Basically we start a graph element then: |
23
|
|
|
|
|
|
|
# [] dump out any attributes of the graph |
24
|
|
|
|
|
|
|
# [] dump out all vertices, with any attributes of each vertex |
25
|
|
|
|
|
|
|
# [] dump out all edges, with any attributes of each edge |
26
|
|
|
|
|
|
|
# And then close the graph element. Ta da! |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
#======================================================================= |
29
|
|
|
|
|
|
|
sub _write_graph |
30
|
|
|
|
|
|
|
{ |
31
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
32
|
1
|
|
|
|
|
2
|
my $graph = shift; |
33
|
1
|
|
|
|
|
1
|
my $FILE = shift; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
1
|
my $v; |
36
|
|
|
|
|
|
|
my $from; |
37
|
0
|
|
|
|
|
0
|
my $to; |
38
|
0
|
|
|
|
|
0
|
my $aref; |
39
|
0
|
|
|
|
|
0
|
my $xmlwriter; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
8
|
$xmlwriter = XML::Writer->new(OUTPUT => $FILE, |
43
|
|
|
|
|
|
|
DATA_MODE => 1, |
44
|
|
|
|
|
|
|
DATA_INDENT => 2); |
45
|
1
|
|
|
|
|
177
|
$xmlwriter->setOutput($FILE); |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
39
|
$xmlwriter->startTag('graph'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
# dump out attributes of the graph, if it has any |
51
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
52
|
1
|
|
|
|
|
59
|
$aref = $graph->get_graph_attributes(); |
53
|
1
|
|
|
|
|
10
|
foreach my $attr (keys %{ $aref }) |
|
1
|
|
|
|
|
4
|
|
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
0
|
$xmlwriter->emptyTag('attribute', |
56
|
|
|
|
|
|
|
'name' => $attr, |
57
|
|
|
|
|
|
|
'value' => $aref->{$attr}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
# dump out vertices of the graph, including any attributes |
62
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
63
|
1
|
|
|
|
|
5
|
foreach $v (sort $graph->vertices) |
64
|
|
|
|
|
|
|
{ |
65
|
5
|
|
|
|
|
271
|
$aref = $graph->get_vertex_attributes($v); |
66
|
|
|
|
|
|
|
|
67
|
5
|
50
|
|
|
|
464
|
if (keys(%{ $aref }) > 0) |
|
5
|
|
|
|
|
11
|
|
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
0
|
$xmlwriter->startTag('node', 'id' => $v); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
foreach my $attr (keys %{ $aref }) |
|
0
|
|
|
|
|
0
|
|
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
0
|
$xmlwriter->emptyTag('attribute', |
74
|
|
|
|
|
|
|
'name' => $attr, |
75
|
|
|
|
|
|
|
'value' => $aref->{$attr}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
0
|
$xmlwriter->endTag('node'); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else |
81
|
|
|
|
|
|
|
{ |
82
|
5
|
|
|
|
|
10
|
$xmlwriter->emptyTag('node', 'id' => $v); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
87
|
|
|
|
|
|
|
# dump out edges of the graph, including any attributes |
88
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
89
|
1
|
|
|
|
|
50
|
foreach my $edge (sort _by_vertex $graph->edges) |
90
|
|
|
|
|
|
|
{ |
91
|
7
|
|
|
|
|
405
|
($from, $to) = @$edge; |
92
|
7
|
|
|
|
|
18
|
$aref = $graph->get_edge_attributes($from, $to); |
93
|
7
|
50
|
|
|
|
2602
|
if (keys(%{ $aref }) > 0) |
|
7
|
|
|
|
|
18
|
|
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
0
|
$xmlwriter->startTag('edge', 'from' => $from, 'to' => $to); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
0
|
foreach my $attr (keys %{ $aref }) |
|
0
|
|
|
|
|
0
|
|
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
0
|
$xmlwriter->emptyTag('attribute', |
100
|
|
|
|
|
|
|
'name' => $attr, |
101
|
|
|
|
|
|
|
'value' => $aref->{$attr}); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
$xmlwriter->endTag('edge'); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else |
107
|
|
|
|
|
|
|
{ |
108
|
7
|
|
|
|
|
19
|
$xmlwriter->emptyTag('edge', 'from' => $from, 'to' => $to); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
71
|
$xmlwriter->endTag('graph'); |
113
|
1
|
|
|
|
|
32
|
$xmlwriter->end(); |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
134
|
return 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _by_vertex |
119
|
|
|
|
|
|
|
{ |
120
|
14
|
|
|
14
|
|
108
|
return $a->[0].$a->[1] cmp $b->[0].$b->[1]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |