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.08'; |
6
|
1
|
|
|
1
|
|
131322
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
708
|
use parent 'Graph::Writer'; |
|
1
|
|
|
|
|
277
|
|
|
1
|
|
|
|
|
5
|
|
11
|
1
|
|
|
1
|
|
1017
|
use XML::Writer; |
|
1
|
|
|
|
|
7162
|
|
|
1
|
|
|
|
|
469
|
|
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
|
|
2
|
my $self = shift; |
31
|
1
|
|
|
|
|
3
|
my $graph = shift; |
32
|
1
|
|
|
|
|
1
|
my $FILE = shift; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
12
|
my $v; |
35
|
|
|
|
|
|
|
my $from; |
36
|
0
|
|
|
|
|
0
|
my $to; |
37
|
0
|
|
|
|
|
0
|
my $aref; |
38
|
0
|
|
|
|
|
0
|
my $xmlwriter; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
10
|
$xmlwriter = XML::Writer->new(OUTPUT => $FILE, |
42
|
|
|
|
|
|
|
DATA_MODE => 1, |
43
|
|
|
|
|
|
|
DATA_INDENT => 2); |
44
|
1
|
|
|
|
|
194
|
$xmlwriter->setOutput($FILE); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
44
|
$xmlwriter->startTag('graph'); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
49
|
|
|
|
|
|
|
# dump out attributes of the graph, if it has any |
50
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
51
|
1
|
|
|
|
|
78
|
$aref = $graph->get_graph_attributes(); |
52
|
1
|
|
|
|
|
11
|
foreach my $attr (keys %{ $aref }) |
|
1
|
|
|
|
|
4
|
|
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
|
|
|
|
|
6
|
foreach $v (sort $graph->vertices) |
63
|
|
|
|
|
|
|
{ |
64
|
5
|
|
|
|
|
386
|
$aref = $graph->get_vertex_attributes($v); |
65
|
|
|
|
|
|
|
|
66
|
5
|
50
|
|
|
|
626
|
if (keys(%{ $aref }) > 0) |
|
5
|
|
|
|
|
22
|
|
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
|
|
|
|
|
15
|
$xmlwriter->emptyTag('node', 'id' => $v); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
86
|
|
|
|
|
|
|
# dump out edges of the graph, including any attributes |
87
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
88
|
1
|
|
|
|
|
70
|
foreach my $edge (sort _by_vertex $graph->edges) |
89
|
|
|
|
|
|
|
{ |
90
|
7
|
|
|
|
|
526
|
($from, $to) = @$edge; |
91
|
7
|
|
|
|
|
24
|
$aref = $graph->get_edge_attributes($from, $to); |
92
|
7
|
50
|
|
|
|
3703
|
if (keys(%{ $aref }) > 0) |
|
7
|
|
|
|
|
20
|
|
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
|
|
|
|
|
22
|
$xmlwriter->emptyTag('edge', 'from' => $from, 'to' => $to); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
90
|
$xmlwriter->endTag('graph'); |
112
|
1
|
|
|
|
|
35
|
$xmlwriter->end(); |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
137
|
return 1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _by_vertex |
118
|
|
|
|
|
|
|
{ |
119
|
12
|
|
|
12
|
|
157
|
return $a->[0].$a->[1] cmp $b->[0].$b->[1]; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |