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