line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Reader::TGF; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
5
|
|
|
5
|
|
84002
|
use base qw(Graph::Reader); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
3093
|
|
5
|
5
|
|
|
5
|
|
32
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
192
|
|
6
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
172
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
5
|
|
|
5
|
|
4979
|
use Encode qw(decode_utf8); |
|
5
|
|
|
|
|
53664
|
|
|
5
|
|
|
|
|
413
|
|
10
|
5
|
|
|
5
|
|
3704
|
use Error::Pure qw(err); |
|
5
|
|
|
|
|
63742
|
|
|
5
|
|
|
|
|
669
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Version. |
13
|
|
|
|
|
|
|
our $VERSION = 0.02; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Edge callback. |
16
|
|
|
|
|
|
|
sub _edge_callback { |
17
|
0
|
|
|
0
|
|
|
my ($self, $graph, $id1, $id2, $edge_label) = @_; |
18
|
0
|
|
|
|
|
|
$graph->set_edge_attribute($id1, $id2, 'label', $edge_label); |
19
|
0
|
|
|
|
|
|
return; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Init. |
23
|
|
|
|
|
|
|
sub _init { |
24
|
0
|
|
|
0
|
|
|
my ($self, $param_hr) = @_; |
25
|
0
|
|
|
|
|
|
$self->SUPER::_init(); |
26
|
0
|
0
|
0
|
|
|
|
if (exists $param_hr->{'edge_callback'} |
|
|
|
0
|
|
|
|
|
27
|
|
|
|
|
|
|
&& defined $param_hr->{'edge_callback'} |
28
|
|
|
|
|
|
|
&& ref $param_hr->{'edge_callback'} ne 'CODE') { |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
err "Parameter 'edge_callback' isn't reference to code."; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
$self->{'edge_callback'} = $param_hr->{'edge_callback'}; |
33
|
0
|
0
|
0
|
|
|
|
if (exists $param_hr->{'vertex_callback'} |
|
|
|
0
|
|
|
|
|
34
|
|
|
|
|
|
|
&& defined $param_hr->{'vertex_callback'} |
35
|
|
|
|
|
|
|
&& ref $param_hr->{'vertex_callback'} ne 'CODE') { |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
err "Parameter 'vertex_callback' isn't reference to code."; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
$self->{'vertex_callback'} = $param_hr->{'vertex_callback'}; |
40
|
0
|
|
|
|
|
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Read graph subroutine. |
44
|
|
|
|
|
|
|
sub _read_graph { |
45
|
0
|
|
|
0
|
|
|
my ($self, $graph, $fh) = @_; |
46
|
0
|
|
|
|
|
|
my $vertexes = 1; |
47
|
0
|
|
|
|
|
|
while (my $line = decode_utf8(<$fh>)) { |
48
|
0
|
|
|
|
|
|
chomp $line; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# End of vertexes section. |
51
|
0
|
0
|
|
|
|
|
if ($line =~ m/^#/ms) { |
52
|
0
|
|
|
|
|
|
$vertexes = 0; |
53
|
0
|
|
|
|
|
|
next; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Vertexes. |
57
|
0
|
0
|
|
|
|
|
if ($vertexes) { |
58
|
0
|
|
|
|
|
|
my ($id, $vertex_label) = split m/\s+/ms, $line, 2; |
59
|
0
|
0
|
|
|
|
|
if (! defined $vertex_label) { |
60
|
0
|
|
|
|
|
|
$vertex_label = $id; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
$graph->add_vertex($id); |
63
|
0
|
0
|
|
|
|
|
if ($self->{'vertex_callback'}) { |
64
|
0
|
|
|
|
|
|
$self->{'vertex_callback'}->($self, $graph, |
65
|
|
|
|
|
|
|
$id, $vertex_label); |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
$self->_vertex_callback($graph, $id, |
68
|
|
|
|
|
|
|
$vertex_label); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Edges. |
72
|
|
|
|
|
|
|
} else { |
73
|
0
|
|
|
|
|
|
my ($id1, $id2, $edge_label) = split m/\s+/ms, $line, 3; |
74
|
0
|
|
|
|
|
|
$graph->add_edge($id1, $id2); |
75
|
0
|
0
|
|
|
|
|
if ($self->{'edge_callback'}) { |
76
|
0
|
|
|
|
|
|
$self->{'edge_callback'}->($self, $graph, $id1, |
77
|
|
|
|
|
|
|
$id2, $edge_label); |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
|
|
|
|
|
$self->_edge_callback($graph, $id1, $id2, |
80
|
|
|
|
|
|
|
$edge_label); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Vertex callback. |
89
|
|
|
|
|
|
|
sub _vertex_callback { |
90
|
0
|
|
|
0
|
|
|
my ($self, $graph, $id, $vertex_label) = @_; |
91
|
0
|
|
|
|
|
|
$graph->set_vertex_attribute($id, 'label', $vertex_label); |
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |